-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Subcommands #4420
Subcommands #4420
Conversation
filebeat/cmd/run.go
Outdated
) | ||
|
||
// RunCmd runs the beat | ||
var RunCmd = &cobra.Command{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason this is not also part of libbeat? Is there anything beat specific about RunCmd
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
beater is the specific part, but now you ask, I could add that as a parameter to GenRootCmd
60b565c
to
7eaf56e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome stuff. Really looking forward to have this in the beats.
@@ -3,12 +3,9 @@ package main | |||
import ( | |||
"os" | |||
|
|||
"github.com/elastic/beats/filebeat/beater" | |||
"github.com/elastic/beats/libbeat/beat" | |||
"github.com/elastic/beats/filebeat/cmd" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change brings up the question if we should also change the generator to support this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
libbeat/beat/beat.go
Outdated
if err != nil { | ||
return err | ||
} | ||
return b.launch(bt) | ||
}()) | ||
} | ||
|
||
// newBeat creates a new beat instance | ||
func newBeat(name, v string) (*Beat, error) { | ||
// NewBeat creates a new beat instance |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder why lint did not complain :-)
Do we have to make this global?
libbeat/cmd/root.go
Outdated
return rootCmd | ||
} | ||
|
||
func init() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would recommend to put the init
on top, at least that is what we did so far.
libbeat/cmd/version.go
Outdated
Use: "version", | ||
Short: "Show current version info", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
beat, err := beat.New(name, "") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I see why we need it global :-)
5209732
to
f68b962
Compare
0fbe954
to
fe28b23
Compare
I wonder how useful is the Here is an example session to show the issue:
|
Interesting that both |
@tsg: Yes, with this change we would have duplicated functionality between subcommands and flags, but purely for backwards compatibility, I'm more in favor of subcommands for all flags that modify run behavior to do a "one shoot" thing. I can include I did some black magic for backwards compatibility, Cobra flags use UNIX style, so it would require |
Ok, I think that's worth a discussion, we could also cut the bandaid with the 6.0 release.
Generally I agree that things that make the Beat stop are better as commands. But the |
I played with it and it feels great to me, nice work. Dumping some thoughts / wishlist, but for future PRs:
|
@@ -44,6 +44,8 @@ https://github.com/elastic/beats/compare/v6.0.0-alpha1...master[Check the HEAD d | |||
|
|||
*Affecting all Beats* | |||
|
|||
- New cli subcommands interface. {pull}4420[4420] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll likely need to deprecate some things, but that can go in a meta ticket.
Thanks for the input, great new ideas!, I didn't think about |
I'll review flags for |
@exekias There will be some doc updates required for this, too (the topic about CLI options and the places where we show commands). Feel free to create a separate issue to track this work, and assign it to me, if you'd like. TBH, when I look at your description above, the syntax is not entirely clear to me. I'm sure it will make more sense when I can play around with the commands in a build (or have time to look more closely at the code). Also, I’m wondering if we’ve taken consistency with other Elastic products (and their command line syntax) into consideration here. Do customers get frustrated when we aren't consistent across products, or am I overthinking this? |
great @dedemorton I will open a new ticket, also input is more than welcomed if you find better naming for any of the added commands. I didn't though about consistency, but it's a good point, I'm going to check how the rest of projects handle this. While I think it's not that important (different projects ==> different ways of using them) perhaps we can achieve something more consistent, which is always good |
@exekias Can you rebase this one, I think it will fix some of the test failures. |
c863e3f
to
f985346
Compare
This change introduces subcommand interface to all beats. This give us several new features: * Isolated subcommands (version, setup, run...) * Command line help for all of them * Autocompletion and typo hinting * Freedom to add beat specific subcommands where needed Usage examples: ``` $ metricbeat help $ metricbeat version $ metricbeat run -h $ metricbeat run -e -v ``` I've kept root command as an alias for `run`, so old style calls should be still working. About flags: Cobra supports persistent (global) and local flags for each command. I've added config related flags as persistent, common to all subcommands. While keeping runtime related flags under `run`, see the full list here: ``` Flags: -N, --N Disable actual publishing for testing --configtest Test configuration and exit. --cpuprofile string Write cpu profile to file -e, --e Log to stderr and disable syslog/file output -h, --help help for run --httpprof string Start pprof http server --memprofile string Write memory profile to this file --setup Load the sample Kibana dashboards -v, --v Log at INFO level --version Print the version and exit Global Flags: -E, --E Flag Configuration overwrite (default null) -c, --c argList Configuration file, relative to path.config (default beat.yml) -d, --d string Enable certain debug selectors --path.config flagOverwrite Configuration path --path.data flagOverwrite Data path --path.home flagOverwrite Home path --path.logs flagOverwrite Logs path --strict.perms Strict permission checking on config files (default true) ``` In the log term we should aim to deprecate a few of them (setup, version, configtest...) in favor of subcommands. I'm keeping them for now to maintain backwards compatibilty with 5.X.
This change introduces subcommand interface to all beats.
This give us several new features:
Usage examples:
I've kept root command as an alias for
run
, so old style calls should be still working.About flags:
Cobra supports persistent (global) and local flags for each command.
I've added config related flags as persistent, common to all
subcommands. While keeping runtime related flags under
run
, see thefull list here:
In the long term we should aim to deprecate a few of them (setup, version, configtest...) in
favor of subcommands. I'm keeping them for now to maintain backwards compatibilty with 5.X.
In progress: