@@ -6,12 +6,14 @@ package cmd
66
77import (
88 "flag"
9- "fmt"
109 "os"
1110 "path/filepath"
1211
1312 "github.com/spf13/cobra"
1413
14+ // import logp flags
15+ _ "github.com/elastic/beats/v7/libbeat/logp/configure"
16+
1517 "github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/application/paths"
1618 "github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/basecmd"
1719 "github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/cli"
@@ -20,23 +22,17 @@ import (
2022const defaultConfig = "elastic-agent.yml"
2123
2224type globalFlags struct {
23- PathConfig string
24- PathConfigFile string
25- FlagStrictPerms bool
25+ PathConfigFile string
2626}
2727
2828// Config returns path which identifies configuration file.
2929func (f * globalFlags ) Config () string {
3030 if len (f .PathConfigFile ) == 0 || f .PathConfigFile == defaultConfig {
31- return filepath .Join (paths .Home (), defaultConfig )
31+ return filepath .Join (paths .Config (), defaultConfig )
3232 }
3333 return f .PathConfigFile
3434}
3535
36- func (f * globalFlags ) StrictPermission () bool {
37- return f .FlagStrictPerms
38- }
39-
4036// NewCommand returns the default command for the agent.
4137func NewCommand () * cobra.Command {
4238 return NewCommandWithArgs (os .Args , cli .NewIOStreams ())
@@ -50,19 +46,26 @@ func NewCommandWithArgs(args []string, streams *cli.IOStreams) *cobra.Command {
5046
5147 flags := & globalFlags {}
5248
49+ // path flags
5350 cmd .PersistentFlags ().AddGoFlag (flag .CommandLine .Lookup ("path.home" ))
51+ cmd .PersistentFlags ().AddGoFlag (flag .CommandLine .Lookup ("path.config" ))
5452 cmd .PersistentFlags ().AddGoFlag (flag .CommandLine .Lookup ("path.data" ))
5553 cmd .PersistentFlags ().AddGoFlag (flag .CommandLine .Lookup ("path.logs" ))
54+ cmd .PersistentFlags ().StringVarP (& flags .PathConfigFile , "c" , "c" , defaultConfig , `Configuration file, relative to path.config` )
5655
57- cmd .PersistentFlags ().StringVarP (& flags .PathConfigFile , "" , "c" , defaultConfig , fmt .Sprintf (`Configuration file, relative to path.config (default "%s")` , defaultConfig ))
58- cmd .PersistentFlags ().StringVarP (& flags .PathConfig , "path.config" , "" , "${path.home}" , "Configuration path" )
59- cmd .PersistentFlags ().BoolVarP (& flags .FlagStrictPerms , "strict.perms" , "" , true , "Strict permission checking on config files" )
56+ // logging flags
57+ cmd .PersistentFlags ().AddGoFlag (flag .CommandLine .Lookup ("v" ))
58+ cmd .PersistentFlags ().AddGoFlag (flag .CommandLine .Lookup ("e" ))
59+ cmd .PersistentFlags ().AddGoFlag (flag .CommandLine .Lookup ("d" ))
60+ cmd .PersistentFlags ().AddGoFlag (flag .CommandLine .Lookup ("environment" ))
6061
61- // Add version.
62+ // subcommands
63+ run := newRunCommandWithArgs (flags , args , streams )
6264 cmd .AddCommand (basecmd .NewDefaultCommandsWithArgs (args , streams )... )
63- cmd .AddCommand (newRunCommandWithArgs ( flags , args , streams ) )
65+ cmd .AddCommand (run )
6466 cmd .AddCommand (newEnrollCommandWithArgs (flags , args , streams ))
6567 cmd .AddCommand (newIntrospectCommandWithArgs (flags , args , streams ))
68+ cmd .Run = run .Run
6669
6770 return cmd
6871}
0 commit comments