Skip to content

Commit

Permalink
Wire up CLI to FML command lines
Browse files Browse the repository at this point in the history
  • Loading branch information
jhugman committed Aug 17, 2023
1 parent b45a761 commit d5f1a4c
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 2 deletions.
9 changes: 8 additions & 1 deletion components/support/nimbus-cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

use std::path::PathBuf;
use std::{ffi::OsString, path::PathBuf};

use chrono::Utc;
use clap::{Args, Parser, Subcommand};
Expand Down Expand Up @@ -176,6 +176,13 @@ pub(crate) enum CliCommand {
list: ExperimentListArgs,
},

/// Execute a nimbus-fml command. See
///
/// nimbus-cli fml -- --help
///
/// for more.
Fml { args: Vec<OsString> },

/// Displays information about an experiment
Info {
#[command(flatten)]
Expand Down
3 changes: 2 additions & 1 deletion components/support/nimbus-cli/src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#[cfg(feature = "server")]
use crate::output::server;
use crate::{
output::deeplink,
output::{deeplink, fml_cli},
protocol::StartAppProtocol,
sources::ManifestSource,
value_utils::{
Expand Down Expand Up @@ -73,6 +73,7 @@ pub(crate) fn process_cmd(cmd: &AppCommand) -> Result<bool> {
)?,

AppCommand::FetchList { list, file } => list.fetch_list(file.as_ref())?,
AppCommand::FmlPassthrough { args, cwd } => fml_cli(args, cwd)?,
AppCommand::Info { experiment, output } => experiment.print_info(output.as_ref())?,
AppCommand::Kill { app } => app.kill_app()?,
AppCommand::List { list, .. } => list.print_list()?,
Expand Down
9 changes: 9 additions & 0 deletions components/support/nimbus-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@ enum AppCommand {
file: Option<PathBuf>,
},

FmlPassthrough {
args: Vec<OsString>,
cwd: PathBuf,
},

Info {
experiment: ExperimentSource,
output: Option<PathBuf>,
Expand Down Expand Up @@ -348,6 +353,10 @@ impl TryFrom<&Cli> for AppCommand {

AppCommand::FetchList { list, file: output }
}
CliCommand::Fml { args } => {
let cwd = std::env::current_dir().expect("Current Working Directory is not set");
AppCommand::FmlPassthrough { args, cwd }
}
CliCommand::Info { experiment, output } => AppCommand::Info {
experiment: ExperimentSource::try_from(&experiment)?,
output,
Expand Down
30 changes: 30 additions & 0 deletions components/support/nimbus-cli/src/output/fml_cli.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

use std::{
ffi::{OsStr, OsString},
path::Path,
vec,
};

use anyhow::Result;
use nimbus_fml::command_line::do_main;

pub(crate) fn fml_cli(args: &Vec<OsString>, cwd: &Path) -> Result<bool> {
// We prepend the string `nimbus-cli fml` to the args to pass to FML
// because the clap uses the 0th argument for help messages.
let first = OsStr::new("nimbus-cli fml").to_os_string();
let mut cli_args = vec![&first];

// To make this a little more ergonomic, if the user has just typed
// `nimbus-cli fml`, then we can help them a little bit.
let help = OsStr::new("--help").to_os_string();
if args.is_empty() {
cli_args.push(&help);
} else {
cli_args.extend(args);
}
do_main(cli_args, cwd)?;
Ok(true)
}
3 changes: 3 additions & 0 deletions components/support/nimbus-cli/src/output/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
pub(crate) mod deeplink;
mod features;
mod fetch;
mod fml_cli;
pub(crate) mod info;
#[cfg(feature = "server")]
pub(crate) mod server;

pub(crate) use fml_cli::fml_cli;

0 comments on commit d5f1a4c

Please sign in to comment.