1- package install
1+ package feature
22
33import (
44 "context"
@@ -9,15 +9,16 @@ import (
99
1010 "github.com/apenella/go-ansible/v2/pkg/execute"
1111 "github.com/apenella/go-ansible/v2/pkg/playbook"
12+ "github.com/kloudkit/ws-cli/internals/styles"
1213 "github.com/spf13/cobra"
1314)
1415
15- var InstallCmd = & cobra.Command {
16+ var installCmd = & cobra.Command {
1617 Use : "install" ,
1718 Short : "Install extra pre-configured features" ,
1819}
1920
20- var features = map [string ]string {
21+ var installableFeatures = map [string ]string {
2122 "cloudflared" : "Install Cloudflare tunnel CLI" ,
2223 "codex" : "Install codex CLI" ,
2324 "conan" : "Install Conan CLI and related tools" ,
@@ -42,7 +43,7 @@ var features = map[string]string{
4243var customCmd = & cobra.Command {
4344 Use : "custom" ,
4445 Short : "Install a custom feature" ,
45- Run : install ("custom" ),
46+ RunE : installFeature ("custom" ),
4647}
4748
4849func runPlay (feature string , vars map [string ]interface {}, errorOut io.Writer ) {
@@ -60,7 +61,8 @@ func runPlay(feature string, vars map[string]interface{}, errorOut io.Writer) {
6061 err := exec .Execute (context .Background ())
6162
6263 if err != nil {
63- fmt .Fprintln (errorOut , err )
64+ fmt .Fprintf (errorOut , "%s\n \n " , styles .ErrorBadge ().Render ("ERROR" ))
65+ fmt .Fprintf (errorOut , "%s\n " , styles .Error ().Render (err .Error ()))
6466 os .Exit (1 )
6567 }
6668}
@@ -69,15 +71,16 @@ func getFeaturePath(root string, feature string, errorOut io.Writer) string {
6971 feature = filepath .Join (root , feature + ".yaml" )
7072
7173 if _ , err := os .Stat (feature ); os .IsNotExist (err ) {
72- fmt .Fprintf (errorOut , "ERROR: The feature path [%s] could not be found.\n " , feature )
74+ fmt .Fprintf (errorOut , "%s\n \n " , styles .ErrorBadge ().Render ("ERROR" ))
75+ fmt .Fprintf (errorOut , "%s\n " , styles .Error ().Render (fmt .Sprintf ("The feature path [%s] could not be found" , feature )))
7376 os .Exit (1 )
7477 }
7578
7679 return feature
7780}
7881
79- func install (feature string ) func (* cobra.Command , []string ) {
80- return func (cmd * cobra.Command , args []string ) {
82+ func installFeature (feature string ) func (* cobra.Command , []string ) error {
83+ return func (cmd * cobra.Command , args []string ) error {
8184 root , _ := cmd .Flags ().GetString ("root" )
8285 rawVars , _ := cmd .Flags ().GetStringToString ("opt" )
8386
@@ -96,11 +99,12 @@ func install(feature string) func(*cobra.Command, []string) {
9699 feature = getFeaturePath (root , feature , cmd .ErrOrStderr ())
97100
98101 runPlay (feature , vars , cmd .ErrOrStderr ())
102+ return nil
99103 }
100104}
101105
102106func init () {
103- InstallCmd .PersistentFlags ().StringToString (
107+ installCmd .PersistentFlags ().StringToString (
104108 "opt" ,
105109 map [string ]string {},
106110 "Optional variables to use during installation" ,
@@ -109,13 +113,13 @@ func init() {
109113 customCmd .Flags ().String ("feature" , "" , "The custom feature to install" )
110114 customCmd .MarkFlagRequired ("feature" )
111115
112- InstallCmd .AddCommand (customCmd )
116+ installCmd .AddCommand (customCmd )
113117
114- for feature , description := range features {
115- InstallCmd .AddCommand (& cobra.Command {
118+ for feature , description := range installableFeatures {
119+ installCmd .AddCommand (& cobra.Command {
116120 Use : feature ,
117121 Short : description ,
118- Run : install (feature ),
122+ RunE : installFeature (feature ),
119123 })
120124 }
121125}
0 commit comments