Simplify CLI code
This commit is contained in:
parent
cd03e06ade
commit
e53ecd93fe
38
Cargo.lock
generated
38
Cargo.lock
generated
@ -200,27 +200,6 @@ version = "0.2.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "67ba02a97a2bd10f4b59b25c7973101c79642302776489e030cd13cdab09ed15"
|
||||
|
||||
[[package]]
|
||||
name = "color-print"
|
||||
version = "0.3.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3aa954171903797d5623e047d9ab69d91b493657917bdfb8c2c80ecaf9cdb6f4"
|
||||
dependencies = [
|
||||
"color-print-proc-macro",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "color-print-proc-macro"
|
||||
version = "0.3.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "692186b5ebe54007e45a59aea47ece9eb4108e141326c304cdc91699a7118a22"
|
||||
dependencies = [
|
||||
"nom",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "colorchoice"
|
||||
version = "1.0.3"
|
||||
@ -339,7 +318,6 @@ name = "dust-cli"
|
||||
version = "0.5.0"
|
||||
dependencies = [
|
||||
"clap 4.5.28",
|
||||
"color-print",
|
||||
"dust-lang",
|
||||
"postcard",
|
||||
"ron",
|
||||
@ -532,22 +510,6 @@ version = "2.7.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
|
||||
|
||||
[[package]]
|
||||
name = "minimal-lexical"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
|
||||
|
||||
[[package]]
|
||||
name = "nom"
|
||||
version = "7.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
"minimal-lexical",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "nu-ansi-term"
|
||||
version = "0.46.0"
|
||||
|
@ -20,7 +20,6 @@ clap = { version = "4.5.14", features = [
|
||||
"help",
|
||||
"wrap_help",
|
||||
] }
|
||||
color-print = "0.3.7"
|
||||
dust-lang = { path = "../dust-lang" }
|
||||
postcard = "1.0.10"
|
||||
ron = "0.8.1"
|
||||
|
@ -11,64 +11,16 @@ use clap::{
|
||||
crate_authors, crate_description, crate_version,
|
||||
error::ErrorKind,
|
||||
};
|
||||
use color_print::{cformat, cstr};
|
||||
use dust_lang::{CompileError, Compiler, DustError, DustString, Lexer, Span, Token, Vm};
|
||||
use tracing::{Level, subscriber::set_global_default};
|
||||
use tracing_subscriber::FmtSubscriber;
|
||||
|
||||
const ABOUT: &str = cstr!(
|
||||
r#"
|
||||
<bright-magenta,bold>Dust CLI
|
||||
────────</>
|
||||
{about}
|
||||
|
||||
<bold>⚙️ Version:</> {version}
|
||||
<bold>🦀 Author:</> {author}
|
||||
<bold>⚖️ License:</> GPL-3.0
|
||||
<bold>🔬 Repository:</> https://git.jeffa.io/jeff/dust
|
||||
"#
|
||||
);
|
||||
|
||||
const PLAIN_ABOUT: &str = r#"
|
||||
{about}
|
||||
"#;
|
||||
|
||||
const USAGE: &str = cstr!(
|
||||
r#"
|
||||
<bright-magenta,bold>Usage:</> {usage}
|
||||
"#
|
||||
);
|
||||
|
||||
const SUBCOMMANDS: &str = cstr!(
|
||||
r#"
|
||||
<bright-magenta,bold>Commands:</>
|
||||
{subcommands}
|
||||
"#
|
||||
);
|
||||
|
||||
const OPTIONS: &str = cstr!(
|
||||
r#"
|
||||
<bright-magenta,bold>Options:</>
|
||||
{options}
|
||||
"#
|
||||
);
|
||||
|
||||
const CREATE_MAIN_HELP_TEMPLATE: fn() -> String =
|
||||
|| cformat!("{ABOUT}{USAGE}{SUBCOMMANDS}{OPTIONS}");
|
||||
|
||||
const CREATE_COMMAND_HELP_TEMPLATE: fn(&str) -> String = |title| {
|
||||
cformat!(
|
||||
"\
|
||||
<bright-magenta,bold>{title}\n────────</>\
|
||||
{PLAIN_ABOUT}{USAGE}{OPTIONS}
|
||||
"
|
||||
)
|
||||
};
|
||||
|
||||
const STYLES: Styles = Styles::styled()
|
||||
.literal(AnsiColor::Cyan.on_default())
|
||||
.placeholder(AnsiColor::Cyan.on_default())
|
||||
.valid(AnsiColor::BrightCyan.on_default())
|
||||
.header(AnsiColor::BrightMagenta.on_default().bold().underline())
|
||||
.usage(AnsiColor::BrightMagenta.on_default().bold().underline())
|
||||
.literal(AnsiColor::BrightCyan.on_default().bold())
|
||||
.placeholder(AnsiColor::BrightCyan.on_default().bold())
|
||||
.valid(AnsiColor::BrightGreen.on_default())
|
||||
.invalid(AnsiColor::BrightYellow.on_default())
|
||||
.error(AnsiColor::BrightRed.on_default());
|
||||
|
||||
@ -78,7 +30,6 @@ const STYLES: Styles = Styles::styled()
|
||||
author = crate_authors!(),
|
||||
about = crate_description!(),
|
||||
color = ColorChoice::Auto,
|
||||
help_template = CREATE_MAIN_HELP_TEMPLATE(),
|
||||
styles = STYLES,
|
||||
)]
|
||||
struct Cli {
|
||||
@ -107,7 +58,7 @@ struct Cli {
|
||||
#[derive(Args)]
|
||||
struct Source {
|
||||
/// Source code to run instead of a file
|
||||
#[arg(short, long, value_hint = ValueHint::Other, value_name = "FORMAT")]
|
||||
#[arg(short, long, value_hint = ValueHint::Other, value_name = "INPUT")]
|
||||
eval: Option<String>,
|
||||
|
||||
/// Read source code from stdin
|
||||
@ -121,10 +72,7 @@ struct Source {
|
||||
|
||||
/// Compile and run the program (default)
|
||||
#[derive(Args)]
|
||||
#[command(
|
||||
short_flag = 'r',
|
||||
help_template = CREATE_COMMAND_HELP_TEMPLATE("Run Mode")
|
||||
)]
|
||||
#[command(short_flag = 'r')]
|
||||
struct Run {
|
||||
/// Print the time taken for compilation and execution
|
||||
#[arg(long)]
|
||||
@ -152,10 +100,7 @@ enum Command {
|
||||
Run(Run),
|
||||
|
||||
/// Compile and print the input
|
||||
#[command(
|
||||
short_flag = 'c',
|
||||
help_template = CREATE_COMMAND_HELP_TEMPLATE("Compile Mode")
|
||||
)]
|
||||
#[command(short_flag = 'c')]
|
||||
Compile {
|
||||
/// Style disassembly output
|
||||
#[arg(short, long, default_value = "true")]
|
||||
@ -173,10 +118,7 @@ enum Command {
|
||||
},
|
||||
|
||||
/// Lex the source code and print the tokens
|
||||
#[command(
|
||||
short_flag = 't',
|
||||
help_template = CREATE_COMMAND_HELP_TEMPLATE("Tokenize Mode")
|
||||
)]
|
||||
#[command(short_flag = 't')]
|
||||
Tokenize {
|
||||
/// Style token output
|
||||
#[arg(short, long, default_value = "true")]
|
||||
|
Loading…
x
Reference in New Issue
Block a user