Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor the Nickel CLI #1502

Merged
merged 11 commits into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ anyhow = "1.0"
assert_cmd = "2.0.11"
assert_matches = "1.5.0"
clap = "4.3"
clap_complete = "4.3.2"
codespan = "0.11"
codespan-lsp = "0.11"
codespan-reporting = "0.11"
Expand All @@ -46,6 +47,7 @@ csv = "1"
derive_more = "0.99"
directories = "4.0.1"
env_logger = "0.10"
git-version = "0.3.5"
indexmap = "1.9.3"
indoc = "2"
insta = "1.29.0"
Expand Down Expand Up @@ -85,7 +87,6 @@ toml = "0.7.2"
typed-arena = "2.0.2"
unicode-segmentation = "1.10.1"
void = "1"
git-version = "0.3.5"

topiary = { version = "0.2.3", git = "https://github.com/tweag/topiary.git", rev = "refs/heads/main" }
# This should be kept in sync with the revision in topiary
Expand Down
3 changes: 2 additions & 1 deletion cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ readme.workspace = true

[[bin]]
name = "nickel"
path = "bin/nickel.rs"
path = "src/main.rs"
bench = false

[features]
Expand All @@ -33,6 +33,7 @@ tree-sitter-nickel = { workspace = true, optional = true }
tempfile = { workspace = true, optional = true }

git-version = { workspace = true }
clap_complete = { workspace = true }

[dev-dependencies]
nickel-lang-utils.workspace = true
Expand Down
248 changes: 0 additions & 248 deletions cli/bin/nickel.rs

This file was deleted.

80 changes: 80 additions & 0 deletions cli/src/cli.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
//! Command-line options and subcommands.
use std::path::PathBuf;

use git_version::git_version;

use crate::{
completions::GenCompletionsCommand, eval::EvalCommand, export::ExportCommand,
pprint_ast::PprintAstCommand, query::QueryCommand, typecheck::TypecheckCommand,
};

#[cfg(feature = "repl")]
use crate::repl::ReplCommand;

#[cfg(feature = "doc")]
use crate::doc::DocCommand;

#[cfg(feature = "format")]
use crate::format::FormatCommand;

#[derive(clap::Parser, Debug)]
/// The interpreter of the Nickel language.
#[command(
author,
about,
long_about = None,
version = format!("{} {} (rev {})", env!("CARGO_BIN_NAME"), env!("CARGO_PKG_VERSION"), git_version!(fallback = env!("NICKEL_NIX_BUILD_REV")))
)]
pub struct Options {
#[command(flatten)]
pub global: GlobalOptions,

#[command(subcommand)]
pub command: Option<Command>,
}

#[derive(clap::Parser, Debug)]
pub struct GlobalOptions {
#[cfg(debug_assertions)]
/// Skips the standard library import. For debugging only. This does not affect REPL
#[arg(long, global = true)]
pub nostdlib: bool,

/// Configure when to output messages in color
#[arg(long, global = true, value_enum, default_value_t)]
pub color: clap::ColorChoice,

/// Input file, omit to read from stdin
#[arg(long, short, global = true)]
pub file: Option<PathBuf>,
}

/// Available subcommands.
#[derive(clap::Subcommand, Debug)]
pub enum Command {
/// Evaluate a Nickel program and pretty-print the result.
#[command(hide = true)]
Eval(EvalCommand),

/// Converts the parsed representation (AST) back to Nickel source code and prints it. Used for
/// debugging purpose
PprintAst(PprintAstCommand),
/// Exports the result to a different format
Export(ExportCommand),
/// Prints the metadata attached to an attribute, given as a path
Query(QueryCommand),
/// Typechecks the program but do not run it
Typecheck(TypecheckCommand),
/// Starts a REPL session
#[cfg(feature = "repl")]
Repl(ReplCommand),
/// Generates the documentation files for the specified nickel file
#[cfg(feature = "doc")]
Doc(DocCommand),
/// Format Nickel files
#[cfg(feature = "format")]
Format(FormatCommand),

/// Generate shell completion files
GenCompletions(GenCompletionsCommand),
}
Loading