Skip to content
This repository has been archived by the owner on Jul 26, 2024. It is now read-only.

Commit

Permalink
feat: Add command to generate folder boilerplate for a new plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Uzaaft committed Jul 21, 2023
1 parent 2989da8 commit 7aea85a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 22 deletions.
19 changes: 18 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,29 @@ mod util;
use anyhow::{Ok, Result};
use std::fmt::Write;

use crate::{astrocommunity::Astrocommunity, opts::get_opts, util::ctrlc_handler};
use crate::{
astrocommunity::Astrocommunity,
opts::{get_opts, Commands},
util::ctrlc_handler,
};

#[tokio::main]
async fn main() -> Result<()> {
ctrlc_handler()?;
let opts = get_opts();
match &opts.commands {
Some(command) => match command {
Commands::New {
astrocommunity_path,
group,
name,
} => {
return opts.create_new_plugin(astrocommunity_path, group, name);
}
},
None => {}
}

println!("Welcome to the astrocommunity cli. Please select the plugins to install by pressing tab. When you're done, press enter and we'll add it to your config.");
let astro = Astrocommunity::new();
let plugins = astro.get_plugins()?;
Expand Down
31 changes: 10 additions & 21 deletions src/opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,28 +36,17 @@ impl Cli {

/// Create a new folder in atrocommunity directory
/// The folder should be:
pub fn create_new_plugin(&self) {
let astrocommunity_dir =
astrocommunity::Astrocommunity::find_astrocommunity_folder().unwrap();
pub fn create_new_plugin(&self, path: &str, group: &str, name: &str) -> Result<()> {
let astrocommunity_dir = astrocommunity::Astrocommunity::find_astrocommunity_folder()?;

let appname = env::var("NVIM_APPNAME").unwrap_or("nvim".to_string());

let args = self.commands.as_ref().unwrap().clone();
match args {
Commands::New {
astrocommunity_path,
group,
name,
} => {
let new_plugin_dir = PathBuf::from(astrocommunity_path).join(group).join(name);
std::fs::create_dir_all(&new_plugin_dir).unwrap();
let new_plugin_file = new_plugin_dir.join("init.lua");
let new_plugin_readme = new_plugin_dir.join("README.md");
std::fs::write(new_plugin_file, "").unwrap();
std::fs::write(new_plugin_readme, "").unwrap();
println!("Created new plugin at {}", new_plugin_dir.to_str().unwrap());
}
}
let new_plugin_dir = PathBuf::from(path).join(group).join(name);
std::fs::create_dir_all(&new_plugin_dir)?;
let new_plugin_file = new_plugin_dir.join("init.lua");
let new_plugin_readme = new_plugin_dir.join("README.md");
std::fs::write(new_plugin_file, "")?;
std::fs::write(new_plugin_readme, "")?;
println!("Created new plugin at {}", new_plugin_dir.to_str().unwrap());
Ok(())
}
}

Expand Down

0 comments on commit 7aea85a

Please sign in to comment.