dev: automated commit - 2025-05-31 17:12:06
This commit is contained in:
parent
b35d327830
commit
2d690bbe1c
1 changed files with 74 additions and 4 deletions
78
main.go
78
main.go
|
@ -37,15 +37,15 @@ type Script struct {
|
||||||
|
|
||||||
var config Config
|
var config Config
|
||||||
|
|
||||||
func log(msg string, args ...interface{}) {
|
func log(msg string, args ...any) {
|
||||||
fmt.Printf(Green+"[RUN]"+NC+" "+msg+"\n", args...)
|
fmt.Printf(Green+"[RUN]"+NC+" "+msg+"\n", args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func warn(msg string, args ...interface{}) {
|
func warn(msg string, args ...any) {
|
||||||
fmt.Printf(Yellow+"[WARN]"+NC+" "+msg+"\n", args...)
|
fmt.Printf(Yellow+"[WARN]"+NC+" "+msg+"\n", args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func errorLog(msg string, args ...interface{}) {
|
func errorLog(msg string, args ...any) {
|
||||||
fmt.Fprintf(os.Stderr, Red+"[ERROR]"+NC+" "+msg+"\n", args...)
|
fmt.Fprintf(os.Stderr, Red+"[ERROR]"+NC+" "+msg+"\n", args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -352,6 +352,21 @@ var rootCmd = &cobra.Command{
|
||||||
var runCmd = &cobra.Command{
|
var runCmd = &cobra.Command{
|
||||||
Use: "run [filters...]",
|
Use: "run [filters...]",
|
||||||
Short: "Run scripts matching filters (or all if no filters)",
|
Short: "Run scripts matching filters (or all if no filters)",
|
||||||
|
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||||
|
scripts, err := findScripts(nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, cobra.ShellCompDirectiveNoFileComp
|
||||||
|
}
|
||||||
|
|
||||||
|
var completions []string
|
||||||
|
for _, script := range scripts {
|
||||||
|
scriptName := strings.TrimSuffix(script.Name, ".sh")
|
||||||
|
if strings.HasPrefix(scriptName, toComplete) {
|
||||||
|
completions = append(completions, scriptName+"\t"+script.Description)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return completions, cobra.ShellCompDirectiveNoFileComp
|
||||||
|
},
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
if err := ensureRunsDir(); err != nil {
|
if err := ensureRunsDir(); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -499,6 +514,61 @@ echo "✅ %s completed successfully"
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var completionCmd = &cobra.Command{
|
||||||
|
Use: "completion [bash|zsh|fish|powershell]",
|
||||||
|
Short: "Generate completion script",
|
||||||
|
Long: `To load completions:
|
||||||
|
|
||||||
|
Bash:
|
||||||
|
$ source <(dev completion bash)
|
||||||
|
|
||||||
|
# To load completions for each session, execute once:
|
||||||
|
# Linux:
|
||||||
|
$ dev completion bash > /etc/bash_completion.d/dev
|
||||||
|
# macOS:
|
||||||
|
$ dev completion bash > $(brew --prefix)/etc/bash_completion.d/dev
|
||||||
|
|
||||||
|
Zsh:
|
||||||
|
# If shell completion is not already enabled in your environment,
|
||||||
|
# you will need to enable it. You can execute the following once:
|
||||||
|
$ echo "autoload -U compinit; compinit" >> ~/.zshrc
|
||||||
|
|
||||||
|
# To load completions for each session, execute once:
|
||||||
|
$ dev completion zsh > "${fpath[1]}/_dev"
|
||||||
|
|
||||||
|
# You will need to start a new shell for this setup to take effect.
|
||||||
|
|
||||||
|
Fish:
|
||||||
|
$ dev completion fish | source
|
||||||
|
|
||||||
|
# To load completions for each session, execute once:
|
||||||
|
$ dev completion fish > ~/.config/fish/completions/dev.fish
|
||||||
|
|
||||||
|
PowerShell:
|
||||||
|
PS> dev completion powershell | Out-String | Invoke-Expression
|
||||||
|
|
||||||
|
# To load completions for every new session, run:
|
||||||
|
PS> dev completion powershell > dev.ps1
|
||||||
|
# and source this file from your PowerShell profile.
|
||||||
|
`,
|
||||||
|
DisableFlagsInUseLine: true,
|
||||||
|
ValidArgs: []string{"bash", "zsh", "fish", "powershell"},
|
||||||
|
Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs),
|
||||||
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
switch args[0] {
|
||||||
|
case "bash":
|
||||||
|
return rootCmd.GenBashCompletion(os.Stdout)
|
||||||
|
case "zsh":
|
||||||
|
return rootCmd.GenZshCompletion(os.Stdout)
|
||||||
|
case "fish":
|
||||||
|
return rootCmd.GenFishCompletion(os.Stdout, true)
|
||||||
|
case "powershell":
|
||||||
|
return rootCmd.GenPowerShellCompletionWithDesc(os.Stdout)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
var depsCmd = &cobra.Command{
|
var depsCmd = &cobra.Command{
|
||||||
Use: "deps",
|
Use: "deps",
|
||||||
Aliases: []string{"check"},
|
Aliases: []string{"check"},
|
||||||
|
@ -514,7 +584,7 @@ func main() {
|
||||||
runCmd.Flags().BoolVar(&config.DryRun, "dry", false, "Show what would run without executing")
|
runCmd.Flags().BoolVar(&config.DryRun, "dry", false, "Show what would run without executing")
|
||||||
runCmd.Flags().BoolVarP(&config.Verbose, "verbose", "v", false, "Show detailed output during execution")
|
runCmd.Flags().BoolVarP(&config.Verbose, "verbose", "v", false, "Show detailed output during execution")
|
||||||
|
|
||||||
rootCmd.AddCommand(runCmd, pushCmd, listCmd, newCmd, depsCmd)
|
rootCmd.AddCommand(runCmd, pushCmd, listCmd, newCmd, depsCmd, completionCmd)
|
||||||
|
|
||||||
if err := rootCmd.Execute(); err != nil {
|
if err := rootCmd.Execute(); err != nil {
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue