Skip to content

Commit

Permalink
feat: add license pasring
Browse files Browse the repository at this point in the history
  • Loading branch information
vhyrro committed Feb 11, 2024
1 parent f4fbb6b commit 4ac60df
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 10 deletions.
10 changes: 10 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions rocks-bin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ nucleo = "0.3.0"
octocrab = "0.34.0"
rocks-lib = { path = "../rocks-lib/" }
rustyline = "13.0.0"
spdx = "0.10.3"
spinners = "4.1.1"
termcolor = "1.4.1"
text_trees = "0.1.2"
Expand Down
32 changes: 22 additions & 10 deletions rocks-bin/src/rockspec/write_rockspec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use clap::Args;
use eyre::{eyre, Result};
use itertools::Itertools;
use rustyline::error::ReadlineError;
use spdx::LicenseId;
use spinners::{Spinner, Spinners};

use crate::rockspec::github_metadata::{self, RepoMetadata};
Expand Down Expand Up @@ -37,8 +38,6 @@ macro_rules! parse {

// General notes and ideas:
// - Should we require the user to create a "project" in order to use this command?
// - Should we grab all collaborators by default? That might end up being massive
// if there's a sizeable project.
// - Ask user for a homepage
// - Automatically detect build type by inspecting the current repo (is there a Cargo.toml? is
// there something that tells us it's a lua project?).
Expand All @@ -61,6 +60,20 @@ fn parse_list(input: String) -> Result<Vec<String>> {
}
}

fn parse_license(input: String) -> Result<Option<LicenseId>> {
match input.to_lowercase().as_str() {
"none" => Ok(None),
_ => Ok(Some(
spdx::imprecise_license_id(&input)
.ok_or(eyre!(
"Unable to identify license '{}', please try again!",
input
))?
.0,
)),
}
}

pub async fn write_rockspec(_data: WriteRockspec) -> Result<()> {
let mut spinner = Spinner::new(Spinners::Dots, "Fetching repository metadata...".into());

Expand Down Expand Up @@ -91,7 +104,6 @@ pub async fn write_rockspec(_data: WriteRockspec) -> Result<()> {
// let mut stdout = BufferedStandardStream::stdout(ColorChoice::Always);
// stdout.set_color(ColorSpec::new().set_fg(Some(Color::Green)))?;

// TODO(vhyrro): Make the array inputs less confusing (mention it being space separated)
let package_name = parse!(
editor.readline(format!("Package Name (empty for '{}'): ", repo_metadata.name).as_str()),
identity,
Expand All @@ -116,19 +128,19 @@ pub async fn write_rockspec(_data: WriteRockspec) -> Result<()> {
let license = parse!(
editor.readline(
format!(
"License (empty for '{}'): ",
"License (empty for '{}', 'none' for no license): ",
repo_metadata
.license
.as_ref()
.unwrap_or(&"*** enter a license ***".to_string())
.unwrap_or(&"none".to_string())
)
.as_str()
),
identity, // TODO: verify license validity
repo_metadata
.license
.unwrap_or("*** enter a license ***".into())
)?;
parse_license,
parse_license(repo_metadata.license.unwrap())?
)?
.map(|license| license.name)
.unwrap_or("*** enter license here ***");

let maintainer = parse!(
editor.readline(
Expand Down

0 comments on commit 4ac60df

Please sign in to comment.