@@ -22,6 +22,7 @@ import (
2222 "koding/klientctl/auth"
2323 "koding/klientctl/config"
2424 "koding/klientctl/ctlcli"
25+ "koding/klientctl/daemon"
2526 "koding/klientctl/endpoint/kloud"
2627 "koding/klientctl/util"
2728
@@ -105,15 +106,32 @@ func run(args []string) {
105106 log .SetLevel (logging .DEBUG )
106107 }
107108
109+ kloud .DefaultLog = log
110+ testKloudHook (kloud .DefaultClient )
111+ defer ctlcli .Close ()
112+
113+ // TODO(leeola): deprecate this default, instead passing it as a dependency
114+ // to the users of it.
115+ //
116+ // init the defaultHealthChecker with the log.
117+ defaultHealthChecker = NewDefaultHealthChecker (log )
118+
108119 // Check if the command the user is giving requires sudo.
109120 if err := AdminRequired (os .Args , sudoRequiredFor , util .NewPermissions ()); err != nil {
110121 // In the event of an error, simply print the error to the user
111122 // and exit.
112- fmt .Println ( "Error: this command requires sudo." )
123+ fmt .Fprintln ( os . Stderr , "This command requires sudo." )
113124 ctlcli .Close ()
114125 os .Exit (10 )
115126 }
116127
128+ if ! daemon .Installed () && ! isDaemonCommand (os .Args [1 :]) {
129+ fmt .Fprintln (os .Stderr , "This command requires a daemon to be installed. Please install it " +
130+ "with the following command:\n \n \t sudo kd daemon install [--team <name>]\n " )
131+ ctlcli .Close ()
132+ os .Exit (1 )
133+ }
134+
117135 sig := make (chan os.Signal , 1 )
118136
119137 go func () {
@@ -124,16 +142,6 @@ func run(args []string) {
124142
125143 signal .Notify (sig , signals ... )
126144
127- kloud .DefaultLog = log
128- testKloudHook (kloud .DefaultClient )
129- defer ctlcli .Close ()
130-
131- // TODO(leeola): deprecate this default, instead passing it as a dependency
132- // to the users of it.
133- //
134- // init the defaultHealthChecker with the log.
135- defaultHealthChecker = NewDefaultHealthChecker (log )
136-
137145 app := cli .NewApp ()
138146 app .Name = config .Name
139147 app .Version = getReadableVersion (config .Version )
@@ -900,3 +908,10 @@ func find(cmds cli.Commands, names ...string) cli.Command {
900908
901909 return cli.Command {}
902910}
911+
912+ func isDaemonCommand (args []string ) bool {
913+ if len (args ) == 0 {
914+ return false
915+ }
916+ return args [0 ] == "daemon"
917+ }
0 commit comments