Projects STRLCPY dum Commits 134b2ca4
🤬
  • Run `cargo clippy` against the codebase

  • Loading...
  • EGOIST committed 2 years ago
    134b2ca4
    1 parent 7945faec
  • ■ ■ ■ ■ ■ ■
    src/args.rs
    skipped 14 lines
    15 15   pub interactive: bool,
    16 16  }
    17 17   
    18  -pub const COMMANDS_TO_FORWARD: &'static [&str] = &["install", "i", "add", "remove", "uninstall"];
     18 +pub const COMMANDS_TO_FORWARD: &[&str] = &["install", "i", "add", "remove", "uninstall"];
    19 19   
    20 20  pub fn parse_args(args_vec: &[String]) -> AppArgs {
    21  - let mut args_iter = args_vec.into_iter();
     21 + let mut args_iter = args_vec.iter();
    22 22   
    23 23   let mut args = AppArgs {
    24 24   script_name: "".to_string(),
    skipped 8 lines
    33 33   match arg {
    34 34   Some(v) => {
    35 35   if v == "--" {
    36  - args.forwarded.push_str(" ");
     36 + args.forwarded.push(' ');
    37 37   args.forwarded
    38 38   .push_str(args_iter.as_slice().join(" ").as_str());
    39 39   break;
    40 40   }
    41  - if v.starts_with("-") {
     41 + if v.starts_with('-') {
    42 42   if args.script_name.is_empty()
    43 43   && (args.command.is_empty() || args.command == "run")
    44 44   {
    skipped 30 lines
    75 75   }
    76 76   } else {
    77 77   // forwarded flags
    78  - args.forwarded.push_str(" ");
    79  - args.forwarded.push_str(&v);
     78 + args.forwarded.push(' ');
     79 + args.forwarded.push_str(v);
    80 80   }
    81 81   } else if args.command.is_empty()
    82 82   && (COMMANDS_TO_FORWARD.contains(&v.as_str()) || v == "run")
    skipped 15 lines
    98 98   eprintln!("You can't pass arguments to interactive mode");
    99 99   exit(1);
    100 100   }
    101  - args.forwarded.push_str(" ");
    102  - args.forwarded.push_str(&v);
     101 + args.forwarded.push(' ');
     102 + args.forwarded.push_str(v);
    103 103   }
    104 104   }
    105 105   None => break,
    skipped 68 lines
  • ■ ■ ■ ■ ■ ■
    src/install.rs
    1 1  use crate::prompt;
    2  -use std::path::PathBuf;
     2 +use std::path::Path;
    3 3   
    4 4  // A function to guess package manager by looking for lock file in current directory only
    5 5  // If yarn.lock is found, it's likely to be a yarn project
    6 6  // If package-lock.json is found, it's likely to be a npm project
    7 7  // If pnpm-lock.yaml is found, it's likely to be a pnpm project
    8 8  // If none of the above is found, return None
    9  -pub fn guess_package_manager(dir: &PathBuf) -> Option<String> {
     9 +pub fn guess_package_manager(dir: &Path) -> Option<String> {
    10 10   let lock_file = dir.join("yarn.lock");
    11 11   if lock_file.exists() {
    12 12   return Some("yarn".to_string());
    skipped 16 lines
  • ■ ■ ■ ■ ■
    src/prompt.rs
    skipped 23 lines
    24 24   
    25 25   show_cursor();
    26 26   
    27  - if selection.is_none() {
    28  - return None;
    29  - }
     27 + selection?;
    30 28   
    31 29   Some(script_names[selection.unwrap()].to_string())
    32 30  }
    skipped 14 lines
  • ■ ■ ■ ■ ■ ■
    src/run.rs
    skipped 8 lines
    9 9  use std::collections::HashMap;
    10 10  use std::env;
    11 11  use std::fs::read_to_string;
    12  -use std::path::PathBuf;
     12 +use std::path::{Path, PathBuf};
    13 13  use std::process::{exit, Command};
    14 14   
    15 15  // Get PATH env and join it with bin_dir
    skipped 13 lines
    29 29  // A function to find the closest file
    30 30  // Starting from current directory
    31 31  // Recusively until it finds the file or reach root directory
    32  -fn find_closest_files(_current_dir: &PathBuf, name: &str, stop_on_first: bool) -> Vec<PathBuf> {
     32 +fn find_closest_files(_current_dir: &Path, name: &str, stop_on_first: bool) -> Vec<PathBuf> {
    33 33   let mut closest_file: Vec<PathBuf> = Vec::new();
    34  - let mut current_dir = _current_dir.clone();
     34 + let mut current_dir = Path::new(_current_dir);
    35 35   loop {
    36 36   let path = current_dir.join(name);
    37 37   
    skipped 4 lines
    42 42   }
    43 43   }
    44 44   match current_dir.parent() {
    45  - Some(p) => current_dir = p.to_path_buf(),
     45 + Some(p) => current_dir = p,
    46 46   None => break,
    47 47   }
    48 48   }
    skipped 25 lines
    74 74   exit(status.code().unwrap_or(1));
    75 75  }
    76 76   
    77  -fn resolve_bin_path(bin_name: &str, dirs: &Vec<PathBuf>) -> Option<PathBuf> {
     77 +fn resolve_bin_path(bin_name: &str, dirs: &[PathBuf]) -> Option<PathBuf> {
    78 78   for dir in dirs {
    79 79   let path = dir.join(bin_name);
    80 80   if path.exists() {
    skipped 84 lines
    165 165   let mut forwarded = app_args.forwarded.clone();
    166 166   
    167 167   if !app_args.interactive && app_args.command == "run" && script_name.is_empty() {
    168  - println!("\nAvailable scripts:\n");
    169  - for (name, value) in scripts.unwrap() {
    170  - println!("{}", name);
    171  - println!(" {}", value);
     168 + match scripts {
     169 + Some(scripts) => {
     170 + println!("\n{}:\n", Style::new().bold().paint("Available scripts"));
     171 + for (name, value) in scripts {
     172 + println!("{}", Purple.paint(name));
     173 + println!(" {}", value.as_str().unwrap());
     174 + }
     175 + return;
     176 + }
     177 + None => {
     178 + eprintln!("No scripts found");
     179 + exit(1);
     180 + }
    172 181   }
    173  - return;
    174 182   }
    175 183   
    176 184   if !script_name.is_empty() && app_args.interactive {
    skipped 41 lines
    218 226   
    219 227   let npm_script = scripts
    220 228   .and_then(|s| s.get(script_name.as_str()))
    221  - .and_then(|script| {
     229 + .map(|script| {
    222 230   let script = script.as_str().map(|script| script.to_string());
    223  - Some(script.unwrap_or_default())
     231 + script.unwrap_or_default()
    224 232   });
    225  - if npm_script.is_some() {
    226  - let script = replace_run_commands(&npm_script.unwrap());
     233 + if let Some(script) = npm_script {
     234 + let script = replace_run_commands(&script);
    227 235   print_script_info(&script_name, &script, &forwarded);
    228 236   let envs = HashMap::from([("PATH".to_string(), get_path_env(bin_dirs))]);
    229 237   run_command(
    skipped 6 lines
    236 244   return;
    237 245   }
    238 246   let resolved_bin = resolve_bin_path(script_name.as_str(), &bin_dirs);
    239  - if resolved_bin.is_some() {
    240  - let bin_path = resolved_bin.unwrap();
    241  - print_script_info(&script_name, &bin_path.to_str().unwrap(), &forwarded);
     247 + if let Some(bin_path) = resolved_bin {
     248 + print_script_info(&script_name, bin_path.to_str().unwrap(), &forwarded);
    242 249   let envs = HashMap::from([("PATH".to_string(), get_path_env(bin_dirs))]);
    243 250   run_command(
    244 251   &[bin_path.to_str().unwrap(), &forwarded],
    skipped 14 lines
Please wait...
Page is in error, reload to recover