nimbus_cli/output/fml_cli.rs
1// This Source Code Form is subject to the terms of the Mozilla Public
2// License, v. 2.0. If a copy of the MPL was not distributed with this
3// file, You can obtain one at https://mozilla.org/MPL/2.0/.
4
5use std::{
6 ffi::{OsStr, OsString},
7 path::Path,
8 vec,
9};
10
11use anyhow::Result;
12use nimbus_fml::command_line::do_main;
13
14pub(crate) fn fml_cli(args: &Vec<OsString>, cwd: &Path) -> Result<bool> {
15 // We prepend the string `nimbus-cli fml` to the args to pass to FML
16 // because the clap uses the 0th argument for help messages; so the FML's command line processor
17 // will report an error with a usage message of `nimbus-cli fml generate [FLAGS] INPUT OUTPUT`.
18 let first = OsStr::new("nimbus-cli fml").to_os_string();
19 let mut cli_args = vec![&first];
20
21 let help = OsStr::new("--help").to_os_string();
22 if args.is_empty() {
23 // If the user has just typed `nimbus-cli fml`– with no further arguments— then the rather unhelpful message
24 // `not implemented: Command not implemented` is displayed. This will change if and when we upgrade the nimbus-fml
25 // to use cli-derive, but until then, we can do a simple thing to make the experience a bit nicer, by adding
26 // the `--help` flag, so the user gets the nimbus-fml command line help.
27 cli_args.push(&help);
28 }
29
30 // Finally, send all the args after `nimbus-cli fml` verbatim to the FML clap cli.
31 cli_args.extend(args);
32 do_main(cli_args, cwd)?;
33 Ok(true)
34}