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"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "67ba02a97a2bd10f4b59b25c7973101c79642302776489e030cd13cdab09ed15"
|
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]]
|
[[package]]
|
||||||
name = "colorchoice"
|
name = "colorchoice"
|
||||||
version = "1.0.3"
|
version = "1.0.3"
|
||||||
@ -339,7 +318,6 @@ name = "dust-cli"
|
|||||||
version = "0.5.0"
|
version = "0.5.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap 4.5.28",
|
"clap 4.5.28",
|
||||||
"color-print",
|
|
||||||
"dust-lang",
|
"dust-lang",
|
||||||
"postcard",
|
"postcard",
|
||||||
"ron",
|
"ron",
|
||||||
@ -532,22 +510,6 @@ version = "2.7.4"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
|
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]]
|
[[package]]
|
||||||
name = "nu-ansi-term"
|
name = "nu-ansi-term"
|
||||||
version = "0.46.0"
|
version = "0.46.0"
|
||||||
|
@ -20,7 +20,6 @@ clap = { version = "4.5.14", features = [
|
|||||||
"help",
|
"help",
|
||||||
"wrap_help",
|
"wrap_help",
|
||||||
] }
|
] }
|
||||||
color-print = "0.3.7"
|
|
||||||
dust-lang = { path = "../dust-lang" }
|
dust-lang = { path = "../dust-lang" }
|
||||||
postcard = "1.0.10"
|
postcard = "1.0.10"
|
||||||
ron = "0.8.1"
|
ron = "0.8.1"
|
||||||
|
@ -11,64 +11,16 @@ use clap::{
|
|||||||
crate_authors, crate_description, crate_version,
|
crate_authors, crate_description, crate_version,
|
||||||
error::ErrorKind,
|
error::ErrorKind,
|
||||||
};
|
};
|
||||||
use color_print::{cformat, cstr};
|
|
||||||
use dust_lang::{CompileError, Compiler, DustError, DustString, Lexer, Span, Token, Vm};
|
use dust_lang::{CompileError, Compiler, DustError, DustString, Lexer, Span, Token, Vm};
|
||||||
use tracing::{Level, subscriber::set_global_default};
|
use tracing::{Level, subscriber::set_global_default};
|
||||||
use tracing_subscriber::FmtSubscriber;
|
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()
|
const STYLES: Styles = Styles::styled()
|
||||||
.literal(AnsiColor::Cyan.on_default())
|
.header(AnsiColor::BrightMagenta.on_default().bold().underline())
|
||||||
.placeholder(AnsiColor::Cyan.on_default())
|
.usage(AnsiColor::BrightMagenta.on_default().bold().underline())
|
||||||
.valid(AnsiColor::BrightCyan.on_default())
|
.literal(AnsiColor::BrightCyan.on_default().bold())
|
||||||
|
.placeholder(AnsiColor::BrightCyan.on_default().bold())
|
||||||
|
.valid(AnsiColor::BrightGreen.on_default())
|
||||||
.invalid(AnsiColor::BrightYellow.on_default())
|
.invalid(AnsiColor::BrightYellow.on_default())
|
||||||
.error(AnsiColor::BrightRed.on_default());
|
.error(AnsiColor::BrightRed.on_default());
|
||||||
|
|
||||||
@ -78,7 +30,6 @@ const STYLES: Styles = Styles::styled()
|
|||||||
author = crate_authors!(),
|
author = crate_authors!(),
|
||||||
about = crate_description!(),
|
about = crate_description!(),
|
||||||
color = ColorChoice::Auto,
|
color = ColorChoice::Auto,
|
||||||
help_template = CREATE_MAIN_HELP_TEMPLATE(),
|
|
||||||
styles = STYLES,
|
styles = STYLES,
|
||||||
)]
|
)]
|
||||||
struct Cli {
|
struct Cli {
|
||||||
@ -107,7 +58,7 @@ struct Cli {
|
|||||||
#[derive(Args)]
|
#[derive(Args)]
|
||||||
struct Source {
|
struct Source {
|
||||||
/// Source code to run instead of a file
|
/// 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>,
|
eval: Option<String>,
|
||||||
|
|
||||||
/// Read source code from stdin
|
/// Read source code from stdin
|
||||||
@ -121,10 +72,7 @@ struct Source {
|
|||||||
|
|
||||||
/// Compile and run the program (default)
|
/// Compile and run the program (default)
|
||||||
#[derive(Args)]
|
#[derive(Args)]
|
||||||
#[command(
|
#[command(short_flag = 'r')]
|
||||||
short_flag = 'r',
|
|
||||||
help_template = CREATE_COMMAND_HELP_TEMPLATE("Run Mode")
|
|
||||||
)]
|
|
||||||
struct Run {
|
struct Run {
|
||||||
/// Print the time taken for compilation and execution
|
/// Print the time taken for compilation and execution
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
@ -152,10 +100,7 @@ enum Command {
|
|||||||
Run(Run),
|
Run(Run),
|
||||||
|
|
||||||
/// Compile and print the input
|
/// Compile and print the input
|
||||||
#[command(
|
#[command(short_flag = 'c')]
|
||||||
short_flag = 'c',
|
|
||||||
help_template = CREATE_COMMAND_HELP_TEMPLATE("Compile Mode")
|
|
||||||
)]
|
|
||||||
Compile {
|
Compile {
|
||||||
/// Style disassembly output
|
/// Style disassembly output
|
||||||
#[arg(short, long, default_value = "true")]
|
#[arg(short, long, default_value = "true")]
|
||||||
@ -173,10 +118,7 @@ enum Command {
|
|||||||
},
|
},
|
||||||
|
|
||||||
/// Lex the source code and print the tokens
|
/// Lex the source code and print the tokens
|
||||||
#[command(
|
#[command(short_flag = 't')]
|
||||||
short_flag = 't',
|
|
||||||
help_template = CREATE_COMMAND_HELP_TEMPLATE("Tokenize Mode")
|
|
||||||
)]
|
|
||||||
Tokenize {
|
Tokenize {
|
||||||
/// Style token output
|
/// Style token output
|
||||||
#[arg(short, long, default_value = "true")]
|
#[arg(short, long, default_value = "true")]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user