Skip to content

Commit

Permalink
[PR Feedback] Order fields and clean cli flag func
Browse files Browse the repository at this point in the history
Signed-off-by: Salim Afiune <afiune@chef.io>
  • Loading branch information
Salim Afiune committed May 17, 2019
1 parent ee30fc0 commit 3835fbf
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 78 deletions.
127 changes: 53 additions & 74 deletions components/hab/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1054,7 +1054,11 @@ pub fn sub_sup_run(feature_flags: FeatureFlag) -> App<'static, 'static> {
"The interval (seconds) on which to run health checks [default: 30]")
);

maybe_add_event_stream_options(sub, feature_flags)
if feature_flags.contains(FeatureFlag::EVENT_STREAM) {
add_event_stream_options(sub)
} else {
sub
}
}

pub fn sub_sup_sh() -> App<'static, 'static> {
Expand Down Expand Up @@ -1172,80 +1176,55 @@ fn sub_svc_unload(feature_flags: FeatureFlag) -> App<'static, 'static> {
//
// For now, though, these at least provide a place to supply the
// information; we can revise as we go.
fn maybe_add_event_stream_options(mut app: App<'static, 'static>,
feature_flags: FeatureFlag)
-> App<'static, 'static> {
if feature_flags.contains(FeatureFlag::EVENT_STREAM) {
app = app.arg(Arg::with_name("EVENT_STREAM_APPLICATION").help("The name of the \
application for event \
stream purposes. This is \
distinct from the \
`--application` flag \
(which may be going \
away), and will be \
attached to all events \
generated by this \
Supervisor.")
.long("event-stream-application")
.required(true)
.takes_value(true)
.validator(non_empty));
app = app.arg(Arg::with_name("EVENT_STREAM_ENVIRONMENT").help("The name of the \
environment for event \
stream purposes. This is \
distinct from the \
`--environment` flag \
(which may be going \
away), and will be \
attached to all events \
generated by this \
Supervisor.")
.long("event-stream-environment")
.required(true)
.takes_value(true)
.validator(non_empty));
app = app.arg(Arg::with_name("EVENT_STREAM_URL").help("The event stream connection \
string (host:port) used by this \
Supervisor to send events to a \
messaging server.")
.long("event-stream-url")
.required(true)
.takes_value(true)
.validator(non_empty));
app = app.arg(Arg::with_name("EVENT_STREAM_SITE").help("The name of the site where this \
Supervisor is running. It is \
used for event stream purposes.")
.long("event-stream-site")
fn add_event_stream_options(app: App<'static, 'static>) -> App<'static, 'static> {
app.arg(Arg::with_name("EVENT_STREAM_APPLICATION").help("The name of the application for \
event stream purposes. This is \
distinct from the `--application` \
flag (which may be going away), and \
will be attached to all events \
generated by this Supervisor.")
.long("event-stream-application")
.required(true)
.takes_value(true)
.validator(non_empty))
.arg(Arg::with_name("EVENT_STREAM_ENVIRONMENT").help("The name of the environment for \
event stream purposes. This is \
distinct from the `--environment` \
flag (which may be going away), and \
will be attached to all events \
generated by this Supervisor.")
.long("event-stream-environment")
.required(true)
.takes_value(true)
.validator(non_empty))
.arg(Arg::with_name("EVENT_STREAM_URL").help("The event stream connection string \
(host:port) used by this Supervisor to send \
events to a messaging server.")
.long("event-stream-url")
.required(true)
.takes_value(true)
.validator(non_empty))
.arg(Arg::with_name("EVENT_STREAM_SITE").help("The name of the site where this Supervisor \
is running. It is used for event stream \
purposes.")
.long("event-stream-site")
.takes_value(true)
.validator(non_empty))
.arg(Arg::with_name(AutomateAuthToken::ARG_NAME).help("An authentication token for \
streaming events to an messaging \
server.")
.long("event-stream-token")
.required(true)
.takes_value(true)
.validator(AutomateAuthToken::validate)
.env(AutomateAuthToken::ENVVAR))
.arg(Arg::with_name(EventStreamMetadata::ARG_NAME).help("An arbitrary key-value pair to \
add to each event generated by \
this Supervisor")
.long("event-meta")
.takes_value(true)
.validator(non_empty));
app = app.arg(
Arg::with_name(AutomateAuthToken::ARG_NAME)
.help(
"An authentication token for \
streaming events to an \
messaging server.",
)
.long("event-stream-token")
.required(true)
.takes_value(true)
.validator(AutomateAuthToken::validate)
.env(AutomateAuthToken::ENVVAR),
);
app = app.arg(
Arg::with_name(EventStreamMetadata::ARG_NAME)
.help(
"An arbitrary key-value pair \
to add to each event \
generated by this Supervisor",
)
.long("event-meta")
.takes_value(true)
.multiple(true)
.validator(EventStreamMetadata::validate),
);
}

app
.multiple(true)
.validator(EventStreamMetadata::validate))
}

// CLAP Validation Functions
Expand Down
8 changes: 4 additions & 4 deletions components/sup/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,10 @@ pub fn init_stream(config: EventStreamConfig, event_core: EventCore) -> Result<(
pub struct EventStreamConfig {
environment: String,
application: String,
site: Option<String>,
meta: EventStreamMetadata,
token: AutomateAuthToken,
url: String,
site: Option<String>,
}

impl<'a> From<&'a ArgMatches<'a>> for EventStreamConfig {
Expand All @@ -112,12 +112,12 @@ impl<'a> From<&'a ArgMatches<'a>> for EventStreamConfig {
application: m.value_of("EVENT_STREAM_APPLICATION")
.map(str::to_string)
.expect("Required option for EventStream feature"),
site: m.value_of("EVENT_STREAM_SITE").map(str::to_string),
meta: EventStreamMetadata::from(m),
token: AutomateAuthToken::from(m),
url: m.value_of("EVENT_STREAM_URL")
.map(str::to_string)
.expect("Required option for EventStream feature"),
site: m.value_of("EVENT_STREAM_SITE").map(str::to_string), }
.expect("Required option for EventStream feature"), }
}
}

Expand Down Expand Up @@ -167,9 +167,9 @@ impl EventCore {
EventCore { supervisor_id: sys.member_id.clone(),
ip_address: sys.gossip_listen(),
fqdn,
site: config.site.clone(),
environment: config.environment.clone(),
application: config.application.clone(),
site: config.site.clone(),
meta: config.meta.clone() }
}
}
Expand Down

0 comments on commit 3835fbf

Please sign in to comment.