mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-03-05 20:49:04 -08:00
50 lines
867 B
Go
50 lines
867 B
Go
package cli
|
|
|
|
import (
|
|
"fmt"
|
|
"oh-my-posh/environment"
|
|
"time"
|
|
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
// getCmd represents the get command
|
|
var getCmd = &cobra.Command{
|
|
Use: "get [shell|millis]",
|
|
Short: "Get a value from oh-my-posh",
|
|
Long: `Get a value from oh-my-posh.
|
|
|
|
This command is used to get the value of the following variables:
|
|
|
|
- shell
|
|
- millis`,
|
|
ValidArgs: []string{
|
|
"millis",
|
|
"shell",
|
|
},
|
|
Args: NoArgsOrOneValidArg,
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
if len(args) == 0 {
|
|
_ = cmd.Help()
|
|
return
|
|
}
|
|
env := &environment.ShellEnvironment{
|
|
Version: cliVersion,
|
|
}
|
|
env.Init()
|
|
defer env.Close()
|
|
switch args[0] {
|
|
case "millis":
|
|
fmt.Print(time.Now().UnixNano() / 1000000)
|
|
case "shell":
|
|
fmt.Println(env.Shell())
|
|
default:
|
|
_ = cmd.Help()
|
|
}
|
|
},
|
|
}
|
|
|
|
func init() { // nolint:gochecknoinits
|
|
rootCmd.AddCommand(getCmd)
|
|
}
|