mod subcommands;
use std::path::PathBuf;
use clap::Parser;
use crate::{Cli, Commands};
#[test]
fn cli_parses_all_subcommands_defaults_and_flags() {
assert!(matches!(
Cli::try_parse_from(["nv", "doctor"]).unwrap().command,
Commands::Doctor
));
assert!(matches!(
Cli::try_parse_from(["nv", "sdk", "path"]).unwrap().command,
Commands::Sdk {
action: crate::sdk::SdkAction::Path { .. }
}
));
assert!(matches!(
Cli::try_parse_from(["nv", "sdk", "verify"]).unwrap().command,
Commands::Sdk {
action: crate::sdk::SdkAction::Verify { .. }
}
));
assert!(matches!(
Cli::try_parse_from(["nv", "sdk", "install", "--version", "0.1.0"])
.unwrap()
.command,
Commands::Sdk {
action: crate::sdk::SdkAction::Install { .. }
}
));
assert!(matches!(
Cli::try_parse_from(["nv", "new", "app", "hello-nv"]).unwrap().command,
Commands::New {
action: crate::new::NewAction::App { .. }
}
));
assert!(matches!(
Cli::try_parse_from(["nv", "init"]).unwrap().command,
Commands::Init { .. }
));
match Cli::try_parse_from([
"nv",
"dev",
"--package",
"my-app",
"--watch",
"src",
"--port",
"9001",
"--skia",
"--pair",
"--pair-udp-port",
"9101",
"--pair-ws-port",
"9102",
"--pair-token",
"secret-dev-token",
])
.unwrap()
.command
{
Commands::Dev {
action,
app_path,
package,
sdk_root,
watch,
host,
port,
web,
web_port,
no_web,
skia,
pair,
pair_udp_port,
pair_ws_port,
pair_token,
auto_ports,
} => {
assert!(action.is_none());
assert!(app_path.is_none());
assert_eq!(package.as_deref(), Some("my-app"));
assert!(sdk_root.is_none());
assert_eq!(watch, vec![PathBuf::from("src")]);
assert_eq!(host, "0.0.0.0");
assert_eq!(port, 9001);
assert!(!web);
assert_eq!(web_port, 8088);
assert!(!no_web);
assert!(skia);
assert!(pair);
assert_eq!(pair_udp_port, 9101);
assert_eq!(pair_ws_port, 9102);
assert_eq!(pair_token.as_deref(), Some("secret-dev-token"));
assert!(!auto_ports);
}
_ => panic!("expected Dev"),
}
match Cli::try_parse_from([
"nv",
"dev",
"packages/modules/camera/example",
"-p",
"nativeview-example-camera-demo",
"--sdk-root",
"/opt/nv",
"--skia",
"--auto-ports",
])
.unwrap()
.command
{
Commands::Dev {
action,
app_path,
package,
sdk_root,
skia,
auto_ports,
..
} => {
assert!(action.is_none());
assert_eq!(
app_path,
Some(PathBuf::from("packages/modules/camera/example"))
);
assert_eq!(package.as_deref(), Some("nativeview-example-camera-demo"));
assert_eq!(sdk_root, Some(PathBuf::from("/opt/nv")));
assert!(skia);
assert!(auto_ports);
}
_ => panic!("expected Dev with positional APP_PATH + -p + --sdk-root"),
}
match Cli::try_parse_from([
"nv",
"dev",
"wait",
"packages/modules/camera/example/src/lib.rs",
"-p",
"nativeview-example-camera-demo",
"--json",
])
.unwrap()
.command
{
Commands::Dev {
action: Some(crate::DevAction::Wait { paths, package, json, .. }),
app_path,
..
} => {
assert!(app_path.is_none());
assert_eq!(
paths,
vec![PathBuf::from("packages/modules/camera/example/src/lib.rs")]
);
assert_eq!(package.as_deref(), Some("nativeview-example-camera-demo"));
assert!(json);
}
_ => panic!("expected Dev::Wait with -p"),
}
match Cli::try_parse_from([
"nv",
"dev",
"wait",
"examples/studio-workspace/src/lib.rs",
"--timeout-ms",
"15000",
"--wait-for",
"ack",
"--require-host",
"--json",
])
.unwrap()
.command
{
Commands::Dev {
action:
Some(crate::DevAction::Wait {
paths,
package,
timeout_ms,
wait_for,
require_host,
json,
}),
..
} => {
assert_eq!(paths, vec![PathBuf::from("examples/studio-workspace/src/lib.rs")]);
assert!(package.is_none());
assert_eq!(timeout_ms, 15_000);
assert_eq!(wait_for, crate::dev::control::WaitForMode::Ack);
assert!(require_host);
assert!(json);
}
_ => panic!("expected Dev::Wait"),
}
match Cli::try_parse_from(["nv", "dev", "status", "--json"]).unwrap().command {
Commands::Dev {
action: Some(crate::DevAction::Status { package, json }),
..
} => {
assert!(package.is_none());
assert!(json);
}
_ => panic!("expected Dev::Status"),
}
match Cli::try_parse_from(["nv", "pair"]).unwrap().command {
Commands::Pair {
dylib,
package,
host,
udp_port,
ws_port,
token,
width,
height,
fps,
} => {
assert!(dylib.is_none());
assert!(package.is_none());
assert_eq!(host, "0.0.0.0");
assert_eq!(udp_port, 8091);
assert_eq!(ws_port, 8092);
assert!(token.is_none());
assert_eq!(width, 393.0);
assert_eq!(height, 852.0);
assert_eq!(fps, 60);
}
_ => panic!("expected Pair defaults"),
}
match Cli::try_parse_from([
"nv",
"pair",
"--dylib",
"target/debug/libnativeview_example_kitchen_sink.dylib",
"--host",
"127.0.0.1",
"--udp-port",
"9091",
"--ws-port",
"9092",
"--token",
"pair-secret",
"--width",
"430",
"--height",
"932",
"--fps",
"120",
])
.unwrap()
.command
{
Commands::Pair {
dylib,
package,
host,
udp_port,
ws_port,
token,
width,
height,
fps,
} => {
assert_eq!(
dylib,
Some(PathBuf::from(
"target/debug/libnativeview_example_kitchen_sink.dylib"
))
);
assert!(package.is_none());
assert_eq!(host, "127.0.0.1");
assert_eq!(udp_port, 9091);
assert_eq!(ws_port, 9092);
assert_eq!(token.as_deref(), Some("pair-secret"));
assert_eq!(width, 430.0);
assert_eq!(height, 932.0);
assert_eq!(fps, 120);
}
_ => panic!("expected Pair custom flags"),
}
}