2022-03-12 22:43:32 -08:00
|
|
|
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) {
|
2022-03-20 22:41:04 -07:00
|
|
|
if len(args) == 0 {
|
|
|
|
_ = cmd.Help()
|
|
|
|
return
|
|
|
|
}
|
2022-03-16 00:47:39 -07:00
|
|
|
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
|
|
|
}
|