ctrl k
  • src/astrocommunity.rs
    ■ ■ ■ ■ ■ ■
    skipped 15 lines
    16 16   )
    17 17  });
    18 18   
    19  -static REPO_PATH_PREFIX: &str = "lua/astrocommunity/";
    20  - 
    21  -#[derive(Debug, Deserialize)]
    22  -struct Tree {
    23  - tree: Vec<String>,
    24  -}
    25  - 
    26 19  #[derive(Debug, Clone, Hash, Eq, PartialEq, PartialOrd, Ord)]
    27 20  pub struct PluginInfo {
    28 21   pub group: String,
    skipped 69 lines
  • src/git_operations.rs
    ■ ■ ■ ■ ■ ■
    skipped 16 lines
    17 17  const REPO_PATH_PREFIX: &str = "lua/astrocommunity/";
    18 18   
    19 19  #[derive(Debug, Deserialize)]
    20  -struct Tree {
    21  - tree: Vec<RepoContent>,
    22  -}
    23  - 
    24  -#[derive(Debug, Deserialize)]
    25 20  struct RepoContent {
    26  - path: String,
     21 + pub(crate) path: String,
    27 22  }
    28 23   
    29 24  pub struct GitOperations;
    skipped 14 lines
    44 39   output.status.code()
    45 40   ))
    46 41   } else {
    47  - Self::parse_response(output.stdout)
     42 + Self::parse_response(&output.stdout)
    48 43   }
    49 44   }
    50 45   
    51 46   fn parse_response(response: Vec<u8>) -> Result<Vec<PluginInfo>> {
    52  - let tree: Tree = serde_json::from_slice(&response)?;
     47 + let tree: Vec<RepoContent> = serde_json::from_slice(&response)?;
    53 48   let re = Regex::new(r"/[^/]+$")?;
    54 49   
    55 50   // We don't know how many plugins there are, so we'll just allocate the max possible based on the number of files
    56  - let mut plugins = HashSet::with_capacity(tree.tree.len());
    57  - for content in tree.tree {
     51 + let mut plugins = HashSet::with_capacity(tree.len());
     52 + for content in tree {
    58 53   // TODO: Move the replace operations below to parse_plugin_info
    59 54   let path = re.replace(&content.path, "").replace(REPO_PATH_PREFIX, "");
    60 55   if !path.contains(".github") && path != REPO_PATH_PREFIX {
    61  - if let Some(plugin) = Self::parse_plugin_info(path) {
     56 + if let Some(plugin) = parse_plugin_info(path) {
    62 57   plugins.insert(plugin);
    63 58   }
    64 59   }
    65 60   }
    66 61   Ok(plugins.into_iter().collect())
    67 62   }
     63 +}
    68 64   
    69  - fn parse_plugin_info(path: String) -> Option<PluginInfo> {
    70  - let p: Vec<&str> = path.split('/').collect();
    71  - if p.len() >= 2 {
    72  - Some(PluginInfo {
    73  - group: p[0].to_string(),
    74  - name: p[1].to_string(),
    75  - })
    76  - } else {
    77  - None
    78  - }
     65 +fn parse_plugin_info(path: String) -> Option<PluginInfo> {
     66 + let p: Vec<&str> = path.split('/').collect();
     67 + if p.len() < 2 {
     68 + return None;
    79 69   }
     70 + Some(PluginInfo {
     71 + group: p[0].to_string(),
     72 + name: p[1].to_string(),
     73 + })
    80 74  }
    81 75   
  • src/opts.rs
    ■ ■ ■ ■
    1  -use std::{env, path::PathBuf};
     1 +use std::path::PathBuf;
    2 2   
    3 3  use anyhow::Result;
    4 4  use clap::{Args, Parser, Subcommand};
    5 5   
    6 6  use crate::{
    7  - astrocommunity::{self, Astrocommunity},
    8 7   util::{copy_to_clipboard, print_with_syntax},
    9 8  };
    10 9   
    skipped 57 lines
    68 67   /// Create a new folder in atrocommunity directory
    69 68   /// The folder should be:
    70 69   pub fn create_new_plugin(&self, path: &str, group: &str, name: &str) -> Result<()> {
    71  - let astrocommunity_dir = astrocommunity::Astrocommunity::find_astrocommunity_folder()?;
    72  - 
    73 70   let new_plugin_dir = PathBuf::from(path).join(group).join(name);
    74 71   std::fs::create_dir_all(&new_plugin_dir)?;
    75 72   let new_plugin_file = new_plugin_dir.join("init.lua");
    skipped 8 lines
Please wait...
Page is in error, reload to recover