Skip to content
New issue

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

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

Already on GitHub? # to your account

Use Clap V3 instead of StructOpt #850

Merged
merged 3 commits into from
Feb 28, 2022
Merged
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
69 changes: 60 additions & 9 deletions 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 forc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ description = "Fuel Orchestrator."
annotate-snippets = { version = "0.9", features = ["color"] }
ansi_term = "0.12"
anyhow = "1.0.41"
clap = { version = "3.1.2", features = ["env", "derive"] }
dirs = "3.0.2"
flate2 = "1.0.20"
fuel-asm = "0.1"
Expand All @@ -25,7 +26,6 @@ reqwest = { version = "0.11.4", default-features = false, features = ["json", "r
semver = "1.0.3"
serde = {version = "1.0", features = ["derive"]}
serde_json = "1.0.73"
structopt = "0.3"
sway-core = { version = "0.4.0", path = "../sway-core" }
sway-fmt = { version = "0.4.0", path = "../sway-fmt" }
sway-server = { version = "0.4.0", path = "../sway-server" }
Expand Down
12 changes: 6 additions & 6 deletions forc/src/cli/commands/addr2line.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use clap::Parser;
use std::collections::VecDeque;
use std::fs::{self, File};
use std::io::{self, prelude::*, BufReader};
use std::path::{Path, PathBuf};
use structopt::{self, StructOpt};

use annotate_snippets::{
display_list::{DisplayList, FormatOptions},
Expand All @@ -12,19 +12,19 @@ use annotate_snippets::{
use sway_core::source_map::{LocationRange, SourceMap};

/// Show location and context of an opcode address in its source file
#[derive(Debug, StructOpt)]
#[derive(Debug, Parser)]
pub(crate) struct Command {
/// Where to search for the project root
#[structopt(short = "s", long, default_value = ".")]
#[clap(short = 's', long, default_value = ".")]
pub search_dir: PathBuf,
/// Source file mapping in JSON format
#[structopt(short = "g", long)]
#[clap(short = 'g', long)]
pub sourcemap_path: PathBuf,
/// How many lines of context to show
#[structopt(short, long, default_value = "2")]
#[clap(short, long, default_value = "2")]
pub context: usize,
/// Opcode index
#[structopt(short = "i", long)]
#[clap(short = 'i', long)]
pub opcode_index: usize,
}

Expand Down
26 changes: 13 additions & 13 deletions forc/src/cli/commands/build.rs
Original file line number Diff line number Diff line change
@@ -1,50 +1,50 @@
use crate::ops::forc_build;
use structopt::{self, StructOpt};
use clap::Parser;

/// Compile the current or target project.
///
/// The output produced will depend on the project's program type. Building script, predicate and
/// contract projects will produce their bytecode in binary format `<project-name>.bin`. Building
/// contracts and libraries will also produce the public ABI in JSON format
/// `<project-name>-abi.json`.
#[derive(Debug, Default, StructOpt)]
#[derive(Debug, Default, Parser)]
pub struct Command {
/// Path to the project, if not specified, current working directory will be used.
#[structopt(short, long)]
#[clap(short, long)]
pub path: Option<String>,
/// Whether to compile using the IR pipeline.
#[structopt(long)]
#[clap(long)]
pub use_ir: bool,
/// Whether to compile to bytecode (false) or to print out the generated ASM (true).
#[structopt(long)]
#[clap(long)]
pub print_finalized_asm: bool,
/// Whether to compile to bytecode (false) or to print out the generated ASM (true).
#[structopt(long)]
#[clap(long)]
pub print_intermediate_asm: bool,
/// Whether to compile to bytecode (false) or to print out the generated IR (true).
#[structopt(long)]
#[clap(long)]
pub print_ir: bool,
/// If set, outputs a binary file representing the script bytes.
#[structopt(short = "o")]
#[clap(short = 'o')]
pub binary_outfile: Option<String>,
/// If set, outputs source file mapping in JSON format
#[structopt(short = "g", long)]
#[clap(short = 'g', long)]
pub debug_outfile: Option<String>,
/// Offline mode, prevents Forc from using the network when managing dependencies.
/// Meaning it will only try to use previously downloaded dependencies.
#[structopt(long = "offline")]
#[clap(long = "offline")]
pub offline_mode: bool,
/// Silent mode. Don't output any warnings or errors to the command line.
#[structopt(long = "silent", short = "s")]
#[clap(long = "silent", short = 's')]
pub silent_mode: bool,
/// The directory in which the sway compiler output artifacts are placed.
///
/// By default, this is `<project-root>/out`.
#[structopt(long)]
#[clap(long)]
pub output_directory: Option<String>,
/// By default the JSON for ABIs is formatted for human readability. By using this option JSON
/// output will be "minified", i.e. all on one line without whitespace.
#[structopt(long)]
#[clap(long)]
pub minify_json_abi: bool,
}

Expand Down
6 changes: 3 additions & 3 deletions forc/src/cli/commands/clean.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use crate::ops::forc_clean;
use structopt::{self, StructOpt};
use clap::Parser;

/// Removes the default forc compiler output artifact directory, i.e. `<project-name>/out`. Also
/// calls `cargo clean` which removes the `target` directory generated by `cargo` when running
/// tests.
#[derive(Debug, StructOpt)]
#[derive(Debug, Parser)]
pub struct Command {
/// Path to the project, if not specified, current working directory will be used.
#[structopt(short, long)]
#[clap(short, long)]
pub path: Option<String>,
}

Expand Down
26 changes: 13 additions & 13 deletions forc/src/cli/commands/deploy.rs
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
use crate::ops::forc_deploy;
use structopt::{self, StructOpt};
use clap::Parser;

/// Deploy contract project.
/// Crafts a contract deployment transaction then sends it to a running node.
#[derive(Debug, Default, StructOpt)]
#[derive(Debug, Default, Parser)]
pub struct Command {
/// Path to the project, if not specified, current working directory will be used.
#[structopt(short, long)]
#[clap(short, long)]
pub path: Option<String>,
/// Whether to compile using the IR pipeline.
#[structopt(long)]
#[clap(long)]
pub use_ir: bool,
/// Whether to compile to bytecode (false) or to print out the generated ASM (true).
#[structopt(long)]
#[clap(long)]
pub print_finalized_asm: bool,
/// Whether to compile to bytecode (false) or to print out the generated ASM (true).
#[structopt(long)]
#[clap(long)]
pub print_intermediate_asm: bool,
/// Whether to compile to bytecode (false) or to print out the IR (true).
#[structopt(long)]
#[clap(long)]
pub print_ir: bool,
/// If set, outputs a binary file representing the script bytes.
#[structopt(short = "o")]
#[clap(short = 'o')]
pub binary_outfile: Option<String>,
/// If set, outputs source file mapping in JSON format
#[structopt(short = "g", long)]
#[clap(short = 'g', long)]
pub debug_outfile: Option<String>,
/// Offline mode, prevents Forc from using the network when managing dependencies.
/// Meaning it will only try to use previously downloaded dependencies.
#[structopt(long = "offline")]
#[clap(long = "offline")]
pub offline_mode: bool,
/// Silent mode. Don't output any warnings or errors to the command line.
#[structopt(long = "silent", short = "s")]
#[clap(long = "silent", short = 's')]
pub silent_mode: bool,
/// The directory in which the sway compiler output artifacts are placed.
///
/// By default, this is `<project-root>/out`.
#[structopt(long)]
#[clap(long)]
pub output_directory: Option<String>,
/// By default the JSON for ABIs is formatted for human readability. By using this option JSON
/// output will be "minified", i.e. all on one line without whitespace.
#[structopt(long)]
#[clap(long)]
pub minify_json_abi: bool,
}

Expand Down
10 changes: 5 additions & 5 deletions forc/src/cli/commands/explorer.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
use crate::ops::forc_explorer;
use structopt::StructOpt;
use clap::Parser;

/// Run the network explorer.
#[derive(Debug, StructOpt)]
#[derive(Debug, Parser)]
pub struct Command {
/// The port number
#[structopt(short = "p", long = "port", default_value = "3030")]
#[clap(short = 'p', long = "port", default_value = "3030")]
pub port: String,
#[structopt(subcommand)] // Note that we mark a field as a subcommand
#[clap(subcommand)] // Note that we mark a field as a subcommand
pub clean: Option<CleanCommand>,
}

#[derive(Debug, StructOpt)]
#[derive(Debug, Parser)]
pub enum CleanCommand {
Clean,
}
Expand Down
Loading