From 8d45b2a2f59e4c24bbddb13fa55efe10a5f3fe44 Mon Sep 17 00:00:00 2001 From: KtorZ Date: Fri, 28 Oct 2022 15:41:51 +0200 Subject: [PATCH] Enforce ordering of commands/sub-commands according to source By default, clap orders command alphabetically, which can be quite confusing when listing commands with `--help`: ``` SUBCOMMANDS: eval Evaluate an Untyped Plutus Core program flat Encode textual Untyped Plutus Core to flat bytes fmt Format an Untyped Plutus Core program help Print this message or the help of the given subcommand(s) unflat Decode flat bytes to textual Untyped Plutus Cor ``` It is possible to instrument clap to order commands in the same way they are declared in the source, giving us back the freedom to order and group them in a manner that makes sense, e.g.: ``` SUBCOMMANDS: fmt Format an Untyped Plutus Core program eval Evaluate an Untyped Plutus Core program flat Encode textual Untyped Plutus Core to flat bytes unflat Decode flat bytes to textual Untyped Plutus Cor help Print this message or the help of the given subcommand(s) ``` --- crates/cli/src/cmd/tx/mod.rs | 1 + crates/cli/src/cmd/uplc/mod.rs | 1 + crates/cli/src/main.rs | 3 ++- 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/cli/src/cmd/tx/mod.rs b/crates/cli/src/cmd/tx/mod.rs index e2d63a97..ae03fece 100644 --- a/crates/cli/src/cmd/tx/mod.rs +++ b/crates/cli/src/cmd/tx/mod.rs @@ -4,6 +4,7 @@ use clap::Subcommand; /// Commands for working with transactions #[derive(Subcommand)] +#[clap(setting(clap::AppSettings::DeriveDisplayOrder))] pub enum Cmd { Simulate(simulate::Args), } diff --git a/crates/cli/src/cmd/uplc/mod.rs b/crates/cli/src/cmd/uplc/mod.rs index edb1c56b..3aaa8eb7 100644 --- a/crates/cli/src/cmd/uplc/mod.rs +++ b/crates/cli/src/cmd/uplc/mod.rs @@ -7,6 +7,7 @@ use clap::Subcommand; /// Commands for working with untyped Plutus-core #[derive(Subcommand)] +#[clap(setting(clap::AppSettings::DeriveDisplayOrder))] pub enum Cmd { Fmt(fmt::Args), Eval(eval::Args), diff --git a/crates/cli/src/main.rs b/crates/cli/src/main.rs index 2e64ebf1..1862a501 100644 --- a/crates/cli/src/main.rs +++ b/crates/cli/src/main.rs @@ -7,6 +7,7 @@ use cmd::{build, check, new, tx, uplc}; #[derive(Parser)] #[clap(version, about, long_about = None)] #[clap(propagate_version = true)] +#[clap(setting(clap::AppSettings::DeriveDisplayOrder))] pub enum Cmd { New(new::Args), Build(build::Args), @@ -28,9 +29,9 @@ impl Default for Cmd { fn main() -> miette::Result<()> { miette::set_panic_hook(); match Cmd::default() { + Cmd::New(args) => new::exec(args), Cmd::Build(args) => build::exec(args), Cmd::Check(args) => check::exec(args), - Cmd::New(args) => new::exec(args), Cmd::Tx(sub_cmd) => tx::exec(sub_cmd), Cmd::Uplc(sub_cmd) => uplc::exec(sub_cmd), }