@@ -21,7 +21,7 @@ use self::subcommands::render_template::RenderTemplateCommand;
|
||||
pub struct CuddleCli {
|
||||
scripts: Vec<CuddleAction>,
|
||||
variables: Vec<CuddleVariable>,
|
||||
context: Arc<Mutex<Vec<CuddleContext>>>,
|
||||
context: Option<Arc<Mutex<Vec<CuddleContext>>>>,
|
||||
command: Option<Command>,
|
||||
tmp_dir: Option<PathBuf>,
|
||||
config: CuddleConfig,
|
||||
@@ -29,7 +29,7 @@ pub struct CuddleCli {
|
||||
|
||||
impl CuddleCli {
|
||||
pub fn new(
|
||||
context: Arc<Mutex<Vec<CuddleContext>>>,
|
||||
context: Option<Arc<Mutex<Vec<CuddleContext>>>>,
|
||||
config: CuddleConfig,
|
||||
) -> anyhow::Result<CuddleCli> {
|
||||
let mut cli = CuddleCli {
|
||||
@@ -41,17 +41,24 @@ impl CuddleCli {
|
||||
config,
|
||||
};
|
||||
|
||||
cli = cli
|
||||
.process_variables()
|
||||
.process_scripts()
|
||||
.process_templates()?
|
||||
.build_cli();
|
||||
match context {
|
||||
Some(_) => {
|
||||
cli = cli
|
||||
.process_variables()
|
||||
.process_scripts()
|
||||
.process_templates()?
|
||||
.build_cli();
|
||||
}
|
||||
None => {
|
||||
cli = cli.build_bare_cli();
|
||||
}
|
||||
}
|
||||
|
||||
Ok(cli)
|
||||
}
|
||||
|
||||
fn process_variables(mut self) -> Self {
|
||||
if let Ok(context_iter) = self.context.clone().lock() {
|
||||
if let Ok(context_iter) = self.context.clone().unwrap().lock() {
|
||||
for ctx in context_iter.iter() {
|
||||
if let Some(variables) = ctx.plan.vars.clone() {
|
||||
for (name, var) in variables {
|
||||
@@ -87,7 +94,7 @@ impl CuddleCli {
|
||||
}
|
||||
|
||||
fn process_scripts(mut self) -> Self {
|
||||
if let Ok(context_iter) = self.context.clone().lock() {
|
||||
if let Ok(context_iter) = self.context.clone().unwrap().lock() {
|
||||
for ctx in context_iter.iter() {
|
||||
if let Some(scripts) = ctx.plan.scripts.clone() {
|
||||
for (name, script) in scripts {
|
||||
@@ -124,7 +131,7 @@ impl CuddleCli {
|
||||
// Handle all templating with variables and such.
|
||||
// TODO: use actual templating engine, for new we just copy templates to the final folder
|
||||
|
||||
if let Ok(context_iter) = self.context.clone().lock() {
|
||||
if let Ok(context_iter) = self.context.clone().unwrap().lock() {
|
||||
for ctx in context_iter.iter() {
|
||||
let mut template_path = ctx.path.clone();
|
||||
template_path.push("templates");
|
||||
@@ -166,6 +173,22 @@ impl CuddleCli {
|
||||
self
|
||||
}
|
||||
|
||||
fn build_bare_cli(mut self) -> Self {
|
||||
let mut root_cmd = Command::new("cuddle")
|
||||
.version("1.0")
|
||||
.author("kjuulh <contact@kasperhermansen.com>")
|
||||
.about("cuddle is your domain specific organization tool. It enabled widespread sharing through repositories, as well as collaborating while maintaining speed and integrity")
|
||||
.subcommand_required(true)
|
||||
.arg_required_else_help(true)
|
||||
.propagate_version(true);
|
||||
|
||||
root_cmd = subcommands::init::build_command(root_cmd, self.clone());
|
||||
|
||||
self.command = Some(root_cmd);
|
||||
|
||||
self
|
||||
}
|
||||
|
||||
pub fn execute(self) -> anyhow::Result<Self> {
|
||||
if let Some(cli) = self.command.clone() {
|
||||
let matches = cli.clone().get_matches();
|
||||
|
Reference in New Issue
Block a user