Skip to content

Commit

Permalink
Add output for demo and release commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Techassi committed Oct 9, 2023
1 parent 817f868 commit 949a567
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 29 deletions.
49 changes: 34 additions & 15 deletions rust/stackablectl/src/cmds/demo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ impl DemoArgs {

match &self.subcommand {
DemoCommands::List(args) => list_cmd(args, cli, list).await,
DemoCommands::Describe(args) => describe_cmd(args, list).await,
DemoCommands::Describe(args) => describe_cmd(args, cli, list).await,
DemoCommands::Install(args) => install_cmd(args, cli, list, &transfer_client).await,
}
}
Expand Down Expand Up @@ -215,7 +215,11 @@ async fn list_cmd(args: &DemoListArgs, cli: &Cli, list: DemoList) -> Result<Stri

/// Describe a specific demo by printing out a table (plain), JSON or YAML
#[instrument]
async fn describe_cmd(args: &DemoDescribeArgs, list: DemoList) -> Result<String, CmdError> {
async fn describe_cmd(
args: &DemoDescribeArgs,
cli: &Cli,
list: DemoList,
) -> Result<String, CmdError> {
info!("Describing demo {}", args.demo_name);

let demo = list.get(&args.demo_name).ok_or(CmdError::NoSuchDemo {
Expand All @@ -239,7 +243,16 @@ async fn describe_cmd(args: &DemoDescribeArgs, list: DemoList) -> Result<String,

// TODO (Techassi): Add parameter output

Ok(table.to_string())
let mut output = cli.output();

output
.add_command_hint(
format!("stackablectl demo install {}", args.demo_name),
"install the demo",
)
.set_output(table.to_string());

Ok(output.render())
}
OutputType::Json => serde_json::to_string(&demo).context(JsonOutputFormatSnafu),
OutputType::Yaml => serde_yaml::to_string(&demo).context(YamlOutputFormatSnafu),
Expand All @@ -250,7 +263,7 @@ async fn describe_cmd(args: &DemoDescribeArgs, list: DemoList) -> Result<String,
#[instrument(skip(list))]
async fn install_cmd(
args: &DemoInstallArgs,
common_args: &Cli,
cli: &Cli,
list: DemoList,
transfer_client: &FileTransferClient,
) -> Result<String, CmdError> {
Expand All @@ -261,14 +274,12 @@ async fn install_cmd(
})?;

// TODO (Techassi): Try to move all this boilerplate code to build the lists out of here
let files = common_args.get_stack_files().context(PathOrUrlParseSnafu)?;
let files = cli.get_stack_files().context(PathOrUrlParseSnafu)?;
let stack_list = StackList::build(&files, transfer_client)
.await
.context(ListSnafu)?;

let files = common_args
.get_release_files()
.context(PathOrUrlParseSnafu)?;
let files = cli.get_release_files().context(PathOrUrlParseSnafu)?;

let release_list = ReleaseList::build(&files, transfer_client)
.await
Expand Down Expand Up @@ -320,22 +331,30 @@ async fn install_cmd(
.await
.context(DemoSnafu)?;

let output = format!(
"Installed demo {}\n\n\
Use \"stackablectl operator installed{}\" to display the installed operators\n\
Use \"stackablectl stacklet list{}\" to display the installed stacklets",
args.demo_name,
let mut output = cli.output();

let operator_cmd = format!(
"stackablectl operator installed{}",
if args.namespaces.operator_namespace.is_some() {
format!(" --operator-namespace {}", operator_namespace)
} else {
"".into()
},
}
);

let stacklet_cmd = format!(
"stackablectl stacklet list{}",
if args.namespaces.product_namespace.is_some() {
format!(" --product-namespace {}", product_namespace)
} else {
"".into()
}
);

Ok(output)
output
.add_command_hint(operator_cmd, "display the installed operators")
.add_command_hint(stacklet_cmd, "display the installed stacklets")
.set_output(format!("Installed demo '{}'", args.demo_name));

Ok(output.render())
}
69 changes: 55 additions & 14 deletions rust/stackablectl/src/cmds/release.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,12 @@ pub enum CmdError {
}

impl ReleaseArgs {
pub async fn run(&self, common_args: &Cli, cache: Cache) -> Result<String, CmdError> {
pub async fn run(&self, cli: &Cli, cache: Cache) -> Result<String, CmdError> {
debug!("Handle release args");

let transfer_client = FileTransferClient::new_with(cache);

let files = common_args
.get_release_files()
.context(PathOrUrlParseSnafu)?;
let files = cli.get_release_files().context(PathOrUrlParseSnafu)?;

let release_list = ReleaseList::build(&files, &transfer_client)
.await
Expand All @@ -147,16 +145,20 @@ impl ReleaseArgs {
}

match &self.subcommand {
ReleaseCommands::List(args) => list_cmd(args, release_list).await,
ReleaseCommands::Describe(args) => describe_cmd(args, release_list).await,
ReleaseCommands::Install(args) => install_cmd(args, common_args, release_list).await,
ReleaseCommands::Uninstall(args) => uninstall_cmd(args, release_list).await,
ReleaseCommands::List(args) => list_cmd(args, cli, release_list).await,
ReleaseCommands::Describe(args) => describe_cmd(args, cli, release_list).await,
ReleaseCommands::Install(args) => install_cmd(args, cli, release_list).await,
ReleaseCommands::Uninstall(args) => uninstall_cmd(args, cli, release_list).await,
}
}
}

#[instrument]
async fn list_cmd(args: &ReleaseListArgs, release_list: ReleaseList) -> Result<String, CmdError> {
async fn list_cmd(
args: &ReleaseListArgs,
cli: &Cli,
release_list: ReleaseList,
) -> Result<String, CmdError> {
info!("Listing releases");

match args.output_type {
Expand All @@ -181,7 +183,20 @@ async fn list_cmd(args: &ReleaseListArgs, release_list: ReleaseList) -> Result<S
]);
}

Ok(table.to_string())
let mut output = cli.output();

output
.add_command_hint(
"stackablectl release describe [OPTIONS] <RELEASE>",
"display further information for the specified release",
)
.add_command_hint(
"stackablectl release install [OPTIONS] <RELEASE>",
"install a release",
)
.set_output(table.to_string());

Ok(output.render())
}
OutputType::Json => serde_json::to_string(&release_list).context(JsonOutputFormatSnafu),
OutputType::Yaml => serde_yaml::to_string(&release_list).context(YamlOutputFormatSnafu),
Expand All @@ -191,6 +206,7 @@ async fn list_cmd(args: &ReleaseListArgs, release_list: ReleaseList) -> Result<S
#[instrument]
async fn describe_cmd(
args: &ReleaseDescribeArgs,
cli: &Cli,
release_list: ReleaseList,
) -> Result<String, CmdError> {
info!("Describing release");
Expand Down Expand Up @@ -224,7 +240,16 @@ async fn describe_cmd(
product_table.to_string().as_str(),
]);

Ok(table.to_string())
let mut output = cli.output();

output
.add_command_hint(
format!("stackablectl release install {}", args.release),
"install the demo",
)
.set_output(table.to_string());

Ok(output.render())
}
OutputType::Json => serde_json::to_string(&release).context(JsonOutputFormatSnafu),
OutputType::Yaml => serde_yaml::to_string(&release).context(YamlOutputFormatSnafu),
Expand All @@ -236,7 +261,7 @@ async fn describe_cmd(
#[instrument]
async fn install_cmd(
args: &ReleaseInstallArgs,
common_args: &Cli,
cli: &Cli,
release_list: ReleaseList,
) -> Result<String, CmdError> {
info!("Installing release");
Expand Down Expand Up @@ -264,14 +289,24 @@ async fn install_cmd(
)
.context(ReleaseInstallSnafu)?;

Ok(format!("Installed release {}", args.release))
let mut output = cli.output();

output
.add_command_hint(
"stackablectl operator installed",
"list installed operators",
)
.set_output(format!("Installed release '{}'", args.release));

Ok(output.render())
}
None => Ok("No such release".into()),
}
}

async fn uninstall_cmd(
args: &ReleaseUninstallArgs,
cli: &Cli,
release_list: ReleaseList,
) -> Result<String, CmdError> {
info!("Installing release");
Expand All @@ -282,7 +317,13 @@ async fn uninstall_cmd(
.uninstall(&args.operator_namespace)
.context(ReleaseUninstallSnafu)?;

Ok(format!("Uninstalled release {}", args.release))
let mut output = cli.output();

output
.add_command_hint("stackablectl release list", "list available releases")
.set_output(format!("Uninstalled release '{}'", args.release));

Ok(output.render())
}
None => Ok("No such release".into()),
}
Expand Down

0 comments on commit 949a567

Please sign in to comment.