Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/cli/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use clap::{Args, Parser, Subcommand};

use crate::features::ProjectFeatureArgs;
use crate::initializers::InitProjectArgs;
use crate::extras::ListItemArgs;

#[derive(Parser)]
pub struct Cli {
Expand Down Expand Up @@ -36,4 +37,7 @@ pub enum Command {

#[clap(name = "feature", about = "Add a feature to the project")]
ProjectFeature(ProjectFeatureArgs),

#[clap(name = "list", about = "List available templates and features")]
ListItems(ListItemArgs)
}
79 changes: 79 additions & 0 deletions src/extras/extras.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
use clap::{Args, Parser, ValueEnum};

use std::{fmt, fmt::Write};

use crate::{
app_config::AppConfig,
};

#[derive(Clone, Copy, PartialEq, Eq, ValueEnum)]
pub enum ListItem {
All,
Templates,
Features,
}

impl fmt::Display for ListItem {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
ListItem::All => {
write!(f, "all")
}
ListItem::Templates => {
write!(f, "templates")
}
ListItem::Features => {
write!(f, "features")
}
}
}
}

#[derive(Args)]
pub struct ListItemArgs {

#[arg(short, long, default_value_t = ListItem::All)]
pub select: ListItem,
}

pub fn list_items(args: ListItemArgs, config: AppConfig) -> Result<(), String> {

let mut out = String::new();

// Gets all available projects that is configured
if args.select == ListItem::Templates || args.select == ListItem::All {
write!(out, "Project templates:\n------------------\n");
let templates = config
.templates
.iter()
.for_each(|t|
write!(out, "Type: {}\nProfile: {}\n\n", t.name, t.profile).unwrap()
);
}

// Gets all available features that are configured
if args.select == ListItem::Features || args.select == ListItem::All {
write!(out, "Feature: Licenses:\n------------------\n");
let features = config
.features
.licenses
.iter()
.for_each(|t|
write!(out, "Name: {}\n\n", t.name).unwrap()
);

write!(out, "Feature: Linters:\n-----------------\n");
let linters = config
.features
.linters
.iter()
.for_each(|t|
write!(out, "Type: {}\n\n", t.name).unwrap()
);
}

// Get all available linters that i
println!("{}", out);

Ok(())
}
5 changes: 5 additions & 0 deletions src/extras/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//! src/extras/mod.rs

pub mod extras;

pub use extras::{ListItem, ListItemArgs, list_items};
21 changes: 18 additions & 3 deletions src/initializers/init_project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,16 @@ impl fmt::Display for InitProjectError {
write!(f, "Invalid template input: {}", e)
}
InitProjectError::FileWrite(e) => {
write!(f, "Template file write erro: {}", e)
write!(f, "Template file write error: {}", e)
}
InitProjectError::NotFound(e) => {
write!(f, "Template files not found: {}", e.display())
}
InitProjectError::MavenProject(e) => {
write!(f, "{}", e)
write!(f, "Maven template project error: {}", e)
}
InitProjectError::AnsibleProject(e) => {
write!(f, "{}", e)
write!(f, "Ansible template project error: {}", e)
}
}
}
Expand Down Expand Up @@ -91,6 +91,9 @@ pub struct InitProjectArgs {

#[arg(long)]
pub settings: Option<Vec<ProjectSetting>>,
//
// #[arg(long)]
// pub list: bool,
}

struct ProjectInitializer {
Expand Down Expand Up @@ -134,6 +137,18 @@ pub fn handle(
config: AppConfig,
cache: AppCache,
) -> Result<(), InitProjectError> {

// // Prints all available projects that is configured
// if args.list {
// config
// .templates
// .iter()
// .for_each(|t|
// println!("{}", t.name)
// );
// return Ok(());
// }

// Ensure the passed project type and given profile, if any, is present in the config file
// before passing it along
let template: PathBuf = config
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ pub mod app_config;
pub mod initializers;
pub mod features;
pub mod utils;
pub mod extras;
6 changes: 6 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use repotools::{
cli,
features::{ProjectFeatureError, project_feature},
initializers::{InitProjectError, init_project},
extras,
};

#[derive(Debug)]
Expand Down Expand Up @@ -81,6 +82,11 @@ fn main() -> Result<(), AppError> {
eprintln!("Could not add feature: {}", e)
}
}
Command::ListItems(args) => {
if let Err(e) = extras::list_items(args, config) {
eprintln!("Could not list items: {}", e)
}
}
}

Ok(())
Expand Down