ctrl k
  • feat: move logic away from using git remote

  • Loading...
  • Uzair Aftab committed 2 years ago
    f48acac2
    1 parent c14448e5
  • src/main.rs
    ■ ■ ■ ■ ■
     1 +mod astrocommunity;
    1 2  mod file_system;
    2 3  mod fzf;
    3 4  mod git_operations;
    skipped 4 lines
    8 9   
    9 10  use itertools::Itertools;
    10 11   
    11  -use cli_clipboard::{ClipboardContext, ClipboardProvider};
    12  -use opts::Cli;
    13  -use util::print_with_syntax;
    14  - 
    15  -use crate::{git_operations::GitOperations, opts::get_opts};
     12 +use crate::{astrocommunity::Astrocommunity, opts::get_opts};
    16 13   
    17 14  #[tokio::main]
    18 15  async fn main() -> Result<()> {
    skipped 4 lines
    23 20   dbg!("Exiting");
    24 21   std::process::exit(0);
    25 22   });
    26  - select_plugins(&opts)
    27  -}
    28  - 
    29  -fn select_plugins(opts: &Cli) -> Result<()> {
    30  - let git_ops = GitOperations::new();
    31  - let plugins = git_ops.get_astrocommunity_tree()?;
    32  - // Convert strings to plugin_name [group_name] format
    33  - let fzf_strings = plugins
    34  - .iter()
    35  - .map(|plugin| plugin.fzf_string.clone())
    36  - .join("\n");
     23 + let astro = Astrocommunity::new();
     24 + let plugins = astro.get_plugins()?;
    37 25   let mut fzf = fzf::Fzf::new()?;
    38  - fzf.write_to_stdin(fzf_strings.as_bytes())?;
    39  - let result = fzf.read_from_stdout()?;
    40  - let selected_plugins = result
    41  - .split('\n')
    42  - .filter(|line| !line.is_empty())
    43  - .map(|line| {
    44  - plugins
    45  - .iter()
    46  - .find(|plugin| plugin.fzf_string == line)
    47  - .unwrap()
    48  - .clone()
    49  - })
    50  - .collect::<Vec<_>>();
    51  - 
     26 + let fzf_string: String = plugins.iter().map(|plugin| plugin.to_string()).join("\n");
     27 + fzf.write_to_stdin(fzf_string.as_bytes())?;
     28 + let selected_plugins = fzf.get_selected_plugins(&plugins)?;
    52 29   let mut import_statement = String::with_capacity(50 * selected_plugins.len());
    53 30   for item in selected_plugins.iter() {
    54 31   import_statement.push_str(&format!(
    skipped 2 lines
    57 34   name = item.name
    58 35   ));
    59 36   }
    60  - // Ask the user if they want the import statement to be added to their clipboard
    61  - match &opts.copy_to_clipboard {
    62  - true => copy_to_clipboard(import_statement)?,
    63  - false => match opts.output {
    64  - true => println!("{}", import_statement),
    65  - false => print_with_syntax(&import_statement),
    66  - },
    67  - }
    68  - Ok(())
    69  -}
    70  - 
    71  -fn copy_to_clipboard(import_statement: String) -> Result<()> {
    72  - let mut ctx: ClipboardContext = ClipboardProvider::new().unwrap();
    73  - ctx.set_contents(import_statement).unwrap();
    74  - println!("Added to clipboard");
     37 + opts.ouput_to_prefered(&import_statement)?;
    75 38   Ok(())
    76 39  }
    77 40   
Please wait...
Page is in error, reload to recover