diff --git a/cmd/ignite/cmd/root.go b/cmd/ignite/cmd/root.go index b169c88da..564eae29b 100644 --- a/cmd/ignite/cmd/root.go +++ b/cmd/ignite/cmd/root.go @@ -39,8 +39,6 @@ func NewIgniteCommand(in io.Reader, out, err io.Writer) *cobra.Command { // Set the desired logging level, now that the flags are parsed logs.Logger.SetLevel(logLevel) - // TODO Some commands do not need to check root - // Currently it seems to be only ignite version that does not require root if isNonRootCommand(cmd.Name(), cmd.Parent().Name()) { return } @@ -53,6 +51,9 @@ func NewIgniteCommand(in io.Reader, out, err io.Writer) *cobra.Command { // Create the directories needed for running util.GenericCheckErr(util.CreateDirectories()) + // Preload necessary providers + util.GenericCheckErr(providers.Populate(ignite.Preload)) + if err := config.ApplyConfiguration(configPath); err != nil { log.Fatal(err) } diff --git a/cmd/ignite/ignite.go b/cmd/ignite/ignite.go index 331b97dd0..1acef4f3b 100644 --- a/cmd/ignite/ignite.go +++ b/cmd/ignite/ignite.go @@ -4,9 +4,6 @@ import ( "os" "github.com/weaveworks/ignite/cmd/ignite/cmd" - "github.com/weaveworks/ignite/pkg/providers" - "github.com/weaveworks/ignite/pkg/providers/ignite" - "github.com/weaveworks/ignite/pkg/util" ) func main() { @@ -17,9 +14,6 @@ func main() { // Run runs the main cobra command of this application func Run() error { - // Preload necessary providers - util.GenericCheckErr(providers.Populate(ignite.Preload)) - c := cmd.NewIgniteCommand(os.Stdin, os.Stdout, os.Stderr) return c.Execute() } diff --git a/cmd/ignited/cmd/root.go b/cmd/ignited/cmd/root.go index ca500debc..911f3203a 100644 --- a/cmd/ignited/cmd/root.go +++ b/cmd/ignited/cmd/root.go @@ -15,7 +15,8 @@ import ( logflag "github.com/weaveworks/ignite/pkg/logs/flag" networkflag "github.com/weaveworks/ignite/pkg/network/flag" "github.com/weaveworks/ignite/pkg/providers" - "github.com/weaveworks/ignite/pkg/providers/ignite" + "github.com/weaveworks/ignite/pkg/providers/ignited" + "github.com/weaveworks/ignite/pkg/util" runtimeflag "github.com/weaveworks/ignite/pkg/runtime/flag" versioncmd "github.com/weaveworks/ignite/pkg/version/cmd" ) @@ -34,12 +35,27 @@ func NewIgnitedCommand(in io.Reader, out, err io.Writer) *cobra.Command { // Set the desired logging level, now that the flags are parsed logs.Logger.SetLevel(logLevel) + if isNonRootCommand(cmd.Name(), cmd.Parent().Name()) { + return + } + + // Ignited needs to run as root for now, see + // https://github.com/weaveworks/ignite/issues/46 + // TODO: Remove this when ready + util.GenericCheckErr(util.TestRoot()) + + // Create the directories needed for running + util.GenericCheckErr(util.CreateDirectories()) + + // Preload necessary providers + util.GenericCheckErr(providers.Populate(ignited.Preload)) + if err := config.ApplyConfiguration(configPath); err != nil { log.Fatal(err) } // Populate the providers after flags have been parsed - if err := providers.Populate(ignite.Providers); err != nil { + if err := providers.Populate(ignited.Providers); err != nil { log.Fatal(err) } }, @@ -60,6 +76,19 @@ func NewIgnitedCommand(in io.Reader, out, err io.Writer) *cobra.Command { return root } +func isNonRootCommand(cmd string, parentCmd string) bool { + if parentCmd != "ignited" { + return false + } + + switch cmd { + case "version", "help", "completion": + return true + } + + return false +} + func addGlobalFlags(fs *pflag.FlagSet) { logflag.LogLevelFlagVar(fs, &logLevel) runtimeflag.RuntimeVar(fs, &providers.RuntimeName) diff --git a/cmd/ignited/ignited.go b/cmd/ignited/ignited.go index f25c3eaf3..23404d537 100644 --- a/cmd/ignited/ignited.go +++ b/cmd/ignited/ignited.go @@ -9,9 +9,6 @@ import ( log "github.com/sirupsen/logrus" "github.com/weaveworks/ignite/cmd/ignited/cmd" "github.com/weaveworks/ignite/pkg/constants" - "github.com/weaveworks/ignite/pkg/providers" - "github.com/weaveworks/ignite/pkg/providers/ignited" - "github.com/weaveworks/ignite/pkg/util" ) func main() { @@ -44,17 +41,6 @@ func cleanup() { // Run runs the main cobra command of this application func Run() error { - // Ignite needs to run as root for now, see - // https://github.com/weaveworks/ignite/issues/46 - // TODO: Remove this when ready - util.GenericCheckErr(util.TestRoot()) - - // Create the directories needed for running - util.GenericCheckErr(util.CreateDirectories()) - - // Preload necessary providers - util.GenericCheckErr(providers.Populate(ignited.Preload)) - c := cmd.NewIgnitedCommand(os.Stdin, os.Stdout, os.Stderr) return c.Execute() }