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
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ homepage = "https://oseda.net"
repository = "https://github.com/oseda-dev/oseda-cli"
readme = "README.md"
name = "oseda-cli"
version = "2.7.0"
version = "3.0.0"
edition = "2021"

[[bin]]
Expand Down
10 changes: 6 additions & 4 deletions Usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ Initialize a new Oseda project in the working directory

###### **Options:**

* `--title <TITLE>`
* `--tags <TAGS>`
* `--color <COLOR>`
* `--template <TEMPLATE>`
* `--title <TITLE>` — Project Title
* `--tags <TAG1,TAG2,...>` — Project Tags [e.g: ComputerScience,Engineering,...]
* `--color <COLOR>` — Project Color [e.g: Red]
* `--template <FORMAT>` — Project Template Format [HTML | Markdown]
* `--license <SPDX_ID>` — OSI License SPDX identifier [e.g: MIT]
* `--description <TEXT>` — Project Description



Expand Down
8 changes: 7 additions & 1 deletion scripts/test-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ cd test


pwd
./oseda init --title ExampleProject --tags economics ComPuterScience --color red --template HTML
./oseda init \
--title ExampleProject \
--tags "economics, ComPuterScience" \
--color red \
--template HTML \
--description "This is an example project" \
--license "gPl-2.0"

mv oseda ExampleProject
4 changes: 4 additions & 0 deletions scripts/update-usage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
# updates the usage.md file based on clap doc comments

cargo run --bin oseda-usage
23 changes: 19 additions & 4 deletions src/cmd/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,32 @@ use crate::{config, template::Template};
/// Options for the `oseda init` command
#[derive(Args, Debug)]
pub struct InitOptions {
#[arg(long)]
// claps 'value_name' does not change the argument name, basically just the value in the help menu,
// e.g --template <FORMAT>

/// Project Title
#[arg(long, value_name = "TITLE")]
pub title: Option<String>,

#[arg(long, num_args = 1.., value_delimiter=' ')]
/// Project Tags [e.g: ComputerScience,Engineering,...]
#[arg(long, value_delimiter = ',', value_name = "TAG1,TAG2,...")]
pub tags: Option<Vec<String>>,

#[arg(long)]
/// Project Color [e.g: Red]
#[arg(long, value_name = "COLOR")]
pub color: Option<String>,

#[arg(long)]
/// Project Template Format [HTML | Markdown]
#[arg(long, value_name = "FORMAT")]
pub template: Option<String>,

/// OSI License SPDX identifier [e.g: MIT]
#[arg(long, value_name = "SPDX_ID")]
pub license: Option<String>,

/// Project Description
#[arg(long, value_name = "TEXT")]
pub description: Option<String>,
}

// embed all the static markdown template files into binary
Expand Down
31 changes: 25 additions & 6 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ pub fn validate_config(
));
}

if conf.description.is_empty() {
if conf.description.is_empty() || conf.description.eq_ignore_ascii_case(DEFAULT_DESCIPTION) {
return Err(OsedaCheckError::MissingDescription(
"Description is missing or empty. Please update the oseda-config.json".to_owned(),
));
Expand Down Expand Up @@ -125,6 +125,9 @@ pub struct OsedaConfig {
pub license: License,
}


const DEFAULT_DESCIPTION: &'static str = "Fill in project description";

pub fn prompt_for_title() -> Result<String, Box<dyn Error>> {
let validator = |input: &str| {
if input.chars().count() < 2 {
Expand Down Expand Up @@ -155,7 +158,7 @@ pub fn create_conf(options: InitOptions) -> Result<OsedaConfig, Box<dyn Error>>
Some(arg_tags) => {
arg_tags
.iter()
.map(|arg_tag| DefinedTag::from_str(arg_tag))
.map(|arg_tag| DefinedTag::from_str(arg_tag.trim()))
.collect::<Result<Vec<DefinedTag>, _>>()
.map_err(|_| "Invalid tag. Custom Tags may be added to the oseda-config.json after initialization".to_string())?
},
Expand All @@ -169,9 +172,26 @@ pub fn create_conf(options: InitOptions) -> Result<OsedaConfig, Box<dyn Error>>
};

let user_name = github::get_config_from_user_git("user.name")
.ok_or("Could not get github username. Please ensure you are signed into github")?;
.ok_or("Could not get GitHub username. Please ensure you are signed into github")?;

let description = match options.description {
Some(desc) => desc,
None => {
DEFAULT_DESCIPTION.to_owned()
},
};


let license = match options.license {
Some(proposed_license) => {
License::try_from(proposed_license.clone()).or_else(|_| {
eprintln!("Error: Invalid license '{}', please select from the following:", proposed_license);
prompt_for_license()
})?
}
None => prompt_for_license()?,
};

let license = prompt_for_license()?;

Ok(OsedaConfig {
title: title.trim().to_owned(),
Expand All @@ -183,8 +203,7 @@ pub fn create_conf(options: InitOptions) -> Result<OsedaConfig, Box<dyn Error>>
last_updated: get_time(),
color: color.into_hex(),
license,
// start them with empty description
description: String::new(),
description
})
}

Expand Down
24 changes: 12 additions & 12 deletions src/license.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,29 @@ pub enum License {
// strum serialize is compatible with serde trait here
// this will basically allow a complex internal license representation
// but with ease of de/serialization with just the spdx id
#[strum(serialize = "Apache-2.0")]
#[strum(serialize = "Apache-2.0", ascii_case_insensitive)]
Apache2_0,
#[strum(serialize = "MIT")]
#[strum(serialize = "MIT", ascii_case_insensitive)]
Mit,
#[strum(serialize = "CDDL-1.0")]
#[strum(serialize = "CDDL-1.0", ascii_case_insensitive)]
Cddl1_0,
#[strum(serialize = "EPL-2.0")]
#[strum(serialize = "EPL-2.0", ascii_case_insensitive)]
Epl2_0,
#[strum(serialize = "GPL-2.0")]
#[strum(serialize = "GPL-2.0", ascii_case_insensitive)]
Gpl2_0,
#[strum(serialize = "GPL-3.0")]
#[strum(serialize = "GPL-3.0", ascii_case_insensitive)]
Gpl3_0,
#[strum(serialize = "LGPL-2.1")]
#[strum(serialize = "LGPL-2.1", ascii_case_insensitive)]
Lgpl2_1,
#[strum(serialize = "LGPL-3.0")]
#[strum(serialize = "LGPL-3.0", ascii_case_insensitive)]
Lgpl3_0,
#[strum(serialize = "LGPL-2.0")]
#[strum(serialize = "LGPL-2.0", ascii_case_insensitive)]
Lgpl2_0,
#[strum(serialize = "MPL-2.0")]
#[strum(serialize = "MPL-2.0", ascii_case_insensitive)]
Mpl2_0,
#[strum(serialize = "BSD-2-Clause")]
#[strum(serialize = "BSD-2-Clause", ascii_case_insensitive)]
Bsd2Clause,
#[strum(serialize = "BSD-3-Clause")]
#[strum(serialize = "BSD-3-Clause", ascii_case_insensitive)]
Bsd3Clause,
}

Expand Down
Loading