feat: migrate to use cobra as cli dep
This commit is contained in:
+21
-13
@@ -1,21 +1,29 @@
|
||||
package cmd
|
||||
|
||||
import "miro/internal/output"
|
||||
import "github.com/spf13/cobra"
|
||||
|
||||
// Run parses top-level CLI args and returns a process exit code.
|
||||
// Run executes the miro CLI and returns a process exit code.
|
||||
func Run(args []string) int {
|
||||
if len(args) == 0 {
|
||||
output.Println("unknown command")
|
||||
rootCmd := newRootCommand()
|
||||
rootCmd.SetArgs(args)
|
||||
|
||||
if err := rootCmd.Execute(); err != nil {
|
||||
return 1
|
||||
}
|
||||
|
||||
switch args[0] {
|
||||
case "init":
|
||||
return runInit(args[1:])
|
||||
case "record":
|
||||
return runRecord(args[1:])
|
||||
default:
|
||||
output.Printf("unknown command: %s\n", args[0])
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func newRootCommand() *cobra.Command {
|
||||
rootCmd := &cobra.Command{
|
||||
Use: "miro",
|
||||
Short: "A lean CLI E2E testing framework.",
|
||||
RunE: func(cmd *cobra.Command, _ []string) error {
|
||||
return cmd.Help()
|
||||
},
|
||||
}
|
||||
|
||||
rootCmd.AddCommand(newInitCommand(), newRecordCommand())
|
||||
|
||||
return rootCmd
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user