oh-my-posh/src/cli/get.go

49 lines
871 B
Go
Raw Normal View History

package cli
2022-03-12 13:04:08 -08:00
import (
"fmt"
"oh-my-posh/environment"
"time"
"github.com/spf13/cobra"
)
// getCmd represents the get command
var getCmd = &cobra.Command{
2022-04-26 14:09:47 -07:00
Use: "get [shell|millis]",
2022-03-19 11:32:40 -07:00
Short: "Get a value from oh-my-posh",
Long: `Get a value from oh-my-posh.
2022-03-12 13:04:08 -08:00
This command is used to get the value of the following variables:
- shell
- millis`,
ValidArgs: []string{
"millis",
"shell",
},
Args: cobra.OnlyValidArgs,
Run: func(cmd *cobra.Command, args []string) {
if len(args) == 0 {
_ = cmd.Help()
return
}
env := &environment.ShellEnvironment{
Version: cliVersion,
}
2022-03-12 13:04:08 -08:00
env.Init(false)
defer env.Close()
switch args[0] {
case "millis":
fmt.Print(time.Now().UnixNano() / 1000000)
case "shell":
fmt.Println(env.Shell())
2022-03-19 11:48:37 -07:00
default:
_ = cmd.Help()
2022-03-12 13:04:08 -08:00
}
},
}
func init() { // nolint:gochecknoinits
2022-03-19 11:32:40 -07:00
rootCmd.AddCommand(getCmd)
2022-03-12 13:04:08 -08:00
}