11package cmd
22
33import (
4- "fmt "
4+ "context "
55 "os"
66
7+ "github.com/charmbracelet/fang"
78 "github.com/kloudkit/ws-cli/cmd/clip"
89 "github.com/kloudkit/ws-cli/cmd/feature"
910 "github.com/kloudkit/ws-cli/cmd/info"
@@ -24,56 +25,21 @@ var rootCmd = &cobra.Command{
2425 SilenceErrors : true ,
2526}
2627
27- var noColor bool
28-
29- var versionCmd = & cobra.Command {
30- Use : "version" ,
31- Short : "Display the installed workspace version" ,
32- RunE : func (cmd * cobra.Command , args []string ) error {
33- fmt .Fprintln (cmd .OutOrStdout (), styles .Value ().Render (info .Version ))
34- return nil
35- },
36- }
37-
3828func Execute () {
39- if err := rootCmd .Execute (); err != nil {
40-
41- fmt .Fprintf (os .Stderr , "%s %s\n " ,
42- styles .ErrorBadge ().Render ("ERROR" ),
43- styles .Error ().Render (err .Error ()),
44- )
45-
46- // Add usage hint for command resolution errors
47- // if strings.Contains(err.Error(), "unknown command") {
48- // fmt.Fprintf(os.Stderr, "Run '%s --help' for usage.\n", rootCmd.Use)
49- // }
29+ ctx := context .Background ()
5030
51- // Print the original error again to maintain the expected behavior
52- // fmt.Fprintf(os.Stderr, "Error: %s\n", err.Error())
31+ fangOptions := []fang.Option {
32+ fang .WithColorSchemeFunc (styles .FrappeColorScheme ),
33+ fang .WithVersion (info .Version ),
34+ fang .WithoutManpage (),
35+ }
5336
37+ if err := fang .Execute (ctx , rootCmd , fangOptions ... ); err != nil {
5438 os .Exit (1 )
5539 }
5640}
5741
5842func init () {
59- rootCmd .PersistentFlags ().BoolVar (& noColor , "no-color" , false , "Disable color output" )
60-
61- rootCmd .SetHelpTemplate (styles .HelpTemplate ())
62- rootCmd .SetUsageTemplate (styles .UsageTemplate ())
63- rootCmd .SetFlagErrorFunc (func (cmd * cobra.Command , err error ) error {
64- return err
65- })
66-
67- cobra .OnInitialize (func () {
68- if _ , exists := os .LookupEnv ("WS_LOGGING_NO_COLOR" ); exists {
69- styles .ColorEnabled = false
70- }
71-
72- if noColor {
73- styles .ColorEnabled = false
74- }
75- })
76-
7743 rootCmd .AddCommand (
7844 clip .ClipCmd ,
7945 feature .FeatureCmd ,
@@ -83,6 +49,5 @@ func init() {
8349 info .InfoCmd ,
8450 log .LogCmd ,
8551 logs .LogsCmd ,
86- versionCmd ,
8752 )
8853}
0 commit comments