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

chore: bump up clap version #72

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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: 5 additions & 5 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: 1.58.1
toolchain: 1.67.1
override: true
components: rustfmt
- name: Run
Expand All @@ -35,7 +35,7 @@ jobs:
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: 1.58.1
toolchain: 1.67.1
override: true
components: clippy
- name: Run
Expand All @@ -50,7 +50,7 @@ jobs:
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: 1.56.1 # MSRV
toolchain: 1.67.1 # MSRV
override: true
- name: Run
run: make ci-msrv
Expand All @@ -64,7 +64,7 @@ jobs:
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: 1.58.1
toolchain: 1.67.1
Copy link
Member

@doitian doitian Apr 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The MSRV in README is 1.41.01.56.1, we should set up matrix to test all minor versions since 1.41.01.56.1, or update the MSRV in README

override: true
- name: Run
run: make ci-crates
Expand All @@ -78,7 +78,7 @@ jobs:
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: 1.58.1
toolchain: 1.67.1
override: true
- name: Run
run: make ci-examples
Expand Down
17 changes: 4 additions & 13 deletions tools/compiler/Cargo.lock

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

2 changes: 1 addition & 1 deletion tools/compiler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ name = "moleculec-rust"
path = "src/compiler-rust.rs"

[dependencies]
clap = { version = "3", features = ["yaml", "cargo"] }
clap = { version = "4", features = ["cargo", "string"] }
which = "4.0.2"
molecule-codegen = { version = "=0.7.5", path = "../codegen", features = ["compiler-plugin"] }

Expand Down
7 changes: 0 additions & 7 deletions tools/compiler/src/cli/compiler-plugin.yaml

This file was deleted.

24 changes: 0 additions & 24 deletions tools/compiler/src/cli/compiler.yaml

This file was deleted.

59 changes: 48 additions & 11 deletions tools/compiler/src/compiler.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#[macro_use]
extern crate clap;

use std::{convert::TryFrom, process, str};
Expand All @@ -21,17 +20,55 @@ pub(crate) mod config {
}

pub(crate) fn build_commandline() -> AppConfig {
let yaml = clap::load_yaml!("cli/compiler.yaml");
let matches = clap::App::from_yaml(yaml)
//let yaml = clap::load_yaml!("cli/compiler.yaml");
let matches = clap::Command::new("Moleculec")
.version(clap::crate_version!())
.about("Schema compiler for molecule.")
.author("Nervos Core Dev <[email protected]>")
.arg(
clap::Arg::new("schema-file")
.long("schema-file")
.num_args(1)
.help("Provide a schema file to compile.")
.required(true)
)
.arg(
clap::Arg::new("language")
.long("language")
.help("Specify a language, then generate source code for the specified language and output the generated code to the stdout.
This parameter actually specifies a plugin to use. It should be a simple word, and the compiler will search for a plugin called \"moleculec-<language>\" in `$PATH`.
If \"<language>\" is \"-\", the compiler will dump the intermediate data of schema to standard output.")
.required(true)
)
.arg(
clap::Arg::new("format")
.long("format")
.help("If \"<language>\" is \"-\", this parameter is used to specify a format for the intermediate data.")
.value_parser(
[
clap::builder::PossibleValue::new("json"),
clap::builder::PossibleValue::new("yaml"),
]
)
)
.get_matches();
AppConfig::from(&matches)
AppConfig::from(matches)
}

impl<'a> From<&'a clap::ArgMatches> for AppConfig {
fn from(matches: &'a clap::ArgMatches) -> Self {
let schema_file = value_t_or_exit!(matches, "schema-file", PathBuf);
let language = value_t_or_exit!(matches, "language", String);
impl From<clap::ArgMatches> for AppConfig {
fn from(matches: clap::ArgMatches) -> Self {
let schema_file = matches
.get_one::<PathBuf>("schema-file")
.unwrap_or_else(|| {
eprintln!("Error: failed to get schema-file from command line args");
process::exit(1);
});

let language = matches.get_one::<String>("language").unwrap_or_else(|| {
eprintln!("Error: failed to get language from command line args");
process::exit(1);
});

if !schema_file.as_path().is_file() {
eprintln!(
"Error: schema-file [{}] should be a file",
Expand All @@ -40,7 +77,7 @@ pub(crate) mod config {
process::exit(1);
}
let output_config = if language == "-" {
let format = value_t!(matches, "format", String).unwrap_or_else(|_| {
let format = matches.get_one::<String>("format").unwrap_or_else(|| {
eprintln!("Error: since language is \"-\", a format is required");
process::exit(1);
});
Expand All @@ -52,7 +89,7 @@ pub(crate) mod config {
}
}
} else {
if value_t!(matches, "format", String).is_ok() {
if matches.get_one::<String>("format").is_none() {
eprintln!("Error: since language is not \"-\", don't specify format");
process::exit(1);
}
Expand All @@ -65,7 +102,7 @@ pub(crate) mod config {
}
};
Self {
schema_file,
schema_file: schema_file.to_path_buf(),
output_config,
}
}
Expand Down
25 changes: 15 additions & 10 deletions tools/compiler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,27 @@ pub struct AppConfig {
format: IntermediateFormat,
}

type RawAppConfig<'a> = (Language, IntermediateFormat, &'a clap::ArgMatches);
type RawAppConfig = (Language, IntermediateFormat, clap::ArgMatches);

pub fn build_commandline(lang: Language, format: IntermediateFormat) -> AppConfig {
let yaml = clap::load_yaml!("cli/compiler-plugin.yaml");
let matches = clap::App::from_yaml(yaml)
.name(format!("Moleculec {} Plugin", lang))
//let yaml = clap::load_yaml!("cli/compiler-plugin.yaml");
let matches = clap::Command::new(format!("Moleculec {} Plugin", lang))
.author("Nervos Core Dev <[email protected]>")
.about("Compiler plugin for molecule to generate code.")
.version(clap::crate_version!())
.arg(
clap::Arg::new("format")
.long("format")
.help("Output the supported format for the intermediate data."),
)
.get_matches();
AppConfig::from(&(lang, format, &matches))
AppConfig::from((lang, format, matches))
}

impl<'a> From<&'a RawAppConfig<'a>> for AppConfig {
fn from(input: &'a RawAppConfig<'a>) -> Self {
impl From<RawAppConfig> for AppConfig {
fn from(input: RawAppConfig) -> Self {
let (lang, format, matches) = input;
let action = if matches.is_present("format") {
let action = if matches.get_flag("format") {
AppAction::DisplayFormat
} else {
let mut input = Vec::new();
Expand All @@ -43,8 +48,8 @@ impl<'a> From<&'a RawAppConfig<'a>> for AppConfig {
};
Self {
action,
lang: *lang,
format: *format,
lang,
format,
}
}
}
Expand Down