Projects STRLCPY dum Commits 8ea69264
🤬
Revision indexing in progress... (symbol navigation in revisions will be accurate after indexed)
  • ■ ■ ■ ■ ■
    CHANGELOG.md
     1 +## v0.1.14
     2 + 
     3 +- Commands like `install` `uninstall` `add` are now handled before npm scripts, previously if there're no scripts or no package.json the command will not be executed.
     4 +- Properly restore cursor after `ctrl-c`.
     5 + 
    1 6  ## v0.1.13
    2 7   
    3 8  - Ability to select npm scripts interactively, with `-i, --interactive` flag
    skipped 38 lines
  • ■ ■ ■ ■ ■ ■
    Cargo.lock
    skipped 11 lines
    12 12  ]
    13 13   
    14 14  [[package]]
     15 +name = "autocfg"
     16 +version = "1.0.1"
     17 +source = "registry+https://github.com/rust-lang/crates.io-index"
     18 +checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a"
     19 + 
     20 +[[package]]
    15 21  name = "bitflags"
    16 22  version = "1.3.2"
    17 23  source = "registry+https://github.com/rust-lang/crates.io-index"
    18 24  checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
     25 + 
     26 +[[package]]
     27 +name = "cc"
     28 +version = "1.0.72"
     29 +source = "registry+https://github.com/rust-lang/crates.io-index"
     30 +checksum = "22a9137b95ea06864e018375b72adfb7db6e6f68cfc8df5a04d00288050485ee"
    19 31   
    20 32  [[package]]
    21 33  name = "cfg-if"
    skipped 17 lines
    39 51  ]
    40 52   
    41 53  [[package]]
     54 +name = "ctrlc"
     55 +version = "3.2.1"
     56 +source = "registry+https://github.com/rust-lang/crates.io-index"
     57 +checksum = "a19c6cedffdc8c03a3346d723eb20bd85a13362bb96dc2ac000842c6381ec7bf"
     58 +dependencies = [
     59 + "nix",
     60 + "winapi",
     61 +]
     62 + 
     63 +[[package]]
    42 64  name = "dialoguer"
    43 65  version = "0.9.0"
    44 66  source = "registry+https://github.com/rust-lang/crates.io-index"
    skipped 7 lines
    52 74   
    53 75  [[package]]
    54 76  name = "dum"
    55  -version = "0.1.13"
     77 +version = "0.1.14"
    56 78  dependencies = [
    57 79   "ansi_term",
     80 + "ctrlc",
    58 81   "dialoguer",
    59 82   "serde_json",
    60 83  ]
    skipped 32 lines
    93 116  version = "0.2.107"
    94 117  source = "registry+https://github.com/rust-lang/crates.io-index"
    95 118  checksum = "fbe5e23404da5b4f555ef85ebed98fb4083e55a00c317800bc2a50ede9f3d219"
     119 + 
     120 +[[package]]
     121 +name = "memoffset"
     122 +version = "0.6.5"
     123 +source = "registry+https://github.com/rust-lang/crates.io-index"
     124 +checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce"
     125 +dependencies = [
     126 + "autocfg",
     127 +]
     128 + 
     129 +[[package]]
     130 +name = "nix"
     131 +version = "0.23.0"
     132 +source = "registry+https://github.com/rust-lang/crates.io-index"
     133 +checksum = "f305c2c2e4c39a82f7bf0bf65fb557f9070ce06781d4f2454295cc34b1c43188"
     134 +dependencies = [
     135 + "bitflags",
     136 + "cc",
     137 + "cfg-if",
     138 + "libc",
     139 + "memoffset",
     140 +]
    96 141   
    97 142  [[package]]
    98 143  name = "once_cell"
    skipped 170 lines
  • ■ ■ ■ ■ ■
    Cargo.toml
    1 1  [package]
    2 2  name = "dum"
    3  -version = "0.1.13"
     3 +version = "0.1.14"
    4 4  edition = "2021"
    5 5  license = "MIT"
    6 6  description = "An npm scripts runner"
    skipped 6 lines
    13 13  serde_json = "1.0"
    14 14  dialoguer = "0.9.0"
    15 15  ansi_term = "0.12.1"
     16 +ctrlc = "3.2.1"
  • ■ ■ ■ ■ ■ ■
    src/args.rs
    skipped 10 lines
    11 11   pub interactive: bool,
    12 12  }
    13 13   
     14 +pub const COMMANDS_TO_FORWARD: &'static [&str] = &["install", "i", "add", "remove", "uninstall"];
     15 + 
    14 16  pub fn parse_args(args_vec: &[String]) -> AppArgs {
    15 17   let mut args_iter = args_vec.into_iter();
    16 18   
    skipped 47 lines
    64 66   args.forwared.push_str(" ");
    65 67   args.forwared.push_str(&v);
    66 68   }
    67  - } else if v == "run" {
    68  - args.command = v.to_string();
     69 + } else if COMMANDS_TO_FORWARD.contains(&v.as_str()) {
     70 + args.command = match v.as_ref() {
     71 + "i" => "install".to_string(),
     72 + _ => v.to_string(),
     73 + };
    69 74   } else if args.script_name.is_empty() {
    70 75   args.script_name = match v.as_ref() {
    71 76   "t" => "test".to_string(),
    72  - "i" => "install".to_string(),
    73 77   _ => v.to_string(),
    74 78   };
    75 79   } else {
    skipped 76 lines
  • ■ ■ ■ ■ ■ ■
    src/main.rs
    skipped 5 lines
    6 6  use std::env;
    7 7   
    8 8  fn main() {
     9 + prompt::handle_ctrlc();
     10 + 
    9 11   let args_vec: Vec<String> = env::args().collect();
    10 12   let args = args::parse_args(&args_vec[1..]);
    11 13   
    skipped 3 lines
  • ■ ■ ■ ■ ■
    src/prompt.rs
    1 1  use dialoguer::console::Term;
    2 2  use dialoguer::{theme::ColorfulTheme, Input, Select};
     3 +use std::process::exit;
     4 + 
     5 +fn show_cursor() {
     6 + Term::stderr().show_cursor().expect("failed to show cursor");
     7 +}
     8 + 
     9 +pub fn handle_ctrlc() {
     10 + ctrlc::set_handler(move || {
     11 + show_cursor();
     12 + exit(1);
     13 + })
     14 + .expect("Error setting Ctrl-C handler");
     15 +}
    3 16   
    4 17  pub fn select(message: &str, script_names: Vec<&str>) -> Option<String> {
    5 18   let selection = Select::with_theme(&ColorfulTheme::default())
    skipped 3 lines
    9 22   .interact_on_opt(&Term::stderr())
    10 23   .ok()?;
    11 24   
    12  - Term::stderr().show_cursor().expect("failed to show cursor");
     25 + show_cursor();
    13 26   
    14 27   if selection.is_none() {
    15 28   return None;
    skipped 2 lines
    18 31   Some(script_names[selection.unwrap()].to_string())
    19 32  }
    20 33   
    21  -pub fn input(message: &str) -> String {
     34 +pub fn input(message: &str) -> Option<String> {
    22 35   let input = Input::<String>::new()
    23 36   .with_prompt(message)
    24 37   .allow_empty(true)
    skipped 1 lines
    26 39   .interact_text_on(&Term::stderr())
    27 40   .ok();
    28 41   
    29  - Term::stderr().show_cursor().expect("failed to show cursor");
     42 + show_cursor();
    30 43   
    31  - input.expect("should have input")
     44 + input
    32 45  }
    33 46   
  • ■ ■ ■ ■ ■ ■
    src/run.rs
    skipped 60 lines
    61 61   ("sh", "-c")
    62 62   };
    63 63   
     64 + // assign the value of options.current_dir to current_dir
    64 65   let status = Command::new(sh)
    65 66   .arg(sh_flag)
    66 67   .arg(args.join(" "))
    skipped 17 lines
    84 85  }
    85 86   
    86 87  pub fn run(app_args: &args::AppArgs) {
     88 + if args::COMMANDS_TO_FORWARD.contains(&app_args.command.as_str()) {
     89 + let pm = install::guess_package_manager(&app_args.change_dir);
     90 + 
     91 + if pm.is_none() {
     92 + eprintln!("Aborted.");
     93 + exit(1);
     94 + }
     95 + 
     96 + run_command(
     97 + &[&pm.unwrap(), &app_args.command, &app_args.forwared],
     98 + &RunOptions {
     99 + current_dir: app_args.change_dir.clone(),
     100 + envs: HashMap::new(),
     101 + },
     102 + );
     103 + return;
     104 + }
     105 + 
    87 106   let pkg_paths = find_closest_files(&app_args.change_dir, "package.json", true);
    88 107   let pkg_path = if pkg_paths.is_empty() {
    89 108   eprintln!("No package.json found");
    skipped 51 lines
    141 160   .keys()
    142 161   .map(|k| k.as_str())
    143 162   .collect::<Vec<&str>>();
    144  - script_name =
    145  - prompt::select("Select an npm script to run", names_vec).expect("nothing was selected");
     163 + script_name = match prompt::select("Select an npm script to run", names_vec) {
     164 + Some(name) => name,
     165 + None => {
     166 + println!("No script selected.");
     167 + return;
     168 + }
     169 + };
    146 170   forwarded = " ".to_string();
    147  - forwarded.push_str(&prompt::input("Enter arguments to pass to the script"));
    148  - }
    149  - 
    150  - // Run npm install if the script_name is "install"
    151  - if ["install", "add", "remove"].contains(&script_name.as_str()) {
    152  - let pm = install::guess_package_manager(&execute_dir);
    153  - 
    154  - if pm.is_none() {
    155  - eprintln!("No package manager found.");
    156  - exit(1);
    157  - }
    158  - 
    159  - run_command(
    160  - &[&pm.unwrap(), &script_name, &forwarded],
    161  - &RunOptions {
    162  - current_dir: execute_dir,
    163  - envs: HashMap::new(),
     171 + forwarded.push_str(
     172 + match &prompt::input("Enter arguments to pass to the script") {
     173 + Some(args) => args,
     174 + None => {
     175 + println!("Aborted.");
     176 + return;
     177 + }
    164 178   },
    165 179   );
    166  - return;
    167 180   }
    168 181   
    169 182   let npm_script = scripts
    skipped 53 lines
Please wait...
Page is in error, reload to recover