Skip to content

Commit

Permalink
Merge pull request #104 from perryrh0dan/next
Browse files Browse the repository at this point in the history
Next
  • Loading branch information
perryrh0dan authored Dec 8, 2020
2 parents 03505db + 1dbb827 commit d0982a2
Show file tree
Hide file tree
Showing 31 changed files with 1,522 additions and 706 deletions.
6 changes: 4 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
"program": "${workspaceRoot}/target/debug/tmpo",
// "args": ["update"],
// "args": ["init", "-r", "https://github.com/perryrh0dan/templates", "-t", "typescript"],
"args": ["repository", "add"],
// "args": ["init", "-r", "default"],
// "args": ["repository", "add"],
// "args": ["template", "add"],
// "args": ["init", "test"],
"args": ["template", "create"],
"cwd": "${workspaceRoot}",
}
]
Expand Down
205 changes: 103 additions & 102 deletions Cargo.lock

Large diffs are not rendered by default.

27 changes: 14 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,42 +1,43 @@
[package]
name = "tmpo"
description = "Command line utility to create new workspaces based on predefined templates"
version = "1.8.3"
version = "2.0.0"
authors = ["Thomas Pöhlmann <thomaspoehlmann96@googlemail.com>"]
edition = "2018"
license = "MIT"

[dependencies]
clap = { version = "3.0.0-beta.2" }
serde = { version = "1.0.104", features = ["derive"] }
serde_json = "1.0.48"
serde_yaml = "0.8.13"
serde = { version = "1.0.118", features = ["derive"] }
serde_json = "1.0.60"
serde_yaml = "0.8.14"
dirs = "3.0.1"
log = "0.4.8"
log = "0.4.11"
log4rs = "0.13.0"
git2 = "0.13"
colored = "2.0.0"
dialoguer = "0.6.2"
dialoguer = "0.7.1"
tempfile = "3.1.0"
flate2 = "1.0.17"
tar = "0.4.29"
handlebars = "3.5.0"
regex = "1.3.9"
url = "2.1.1"
flate2 = "1.0.19"
tar = "0.4.30"
handlebars = "3.5.1"
regex = "1.4.2"
url = "2.2.0"
base64 = "0.13.0"
semver = "0.11.0"

[dependencies.reqwest]
version = "0.10.8"
features = ["blocking", "json"]
default-features = false

[dependencies.self_update]
version = "0.20"
version = "0.22.0"
features = ["archive-tar"]

[target.'cfg(not(windows))'.dependencies]
openssl = { version = "0.10.30", features = ["vendored"] }

[dev-dependencies]
assert_cmd = "1.0.1"
predicates = "1"
predicates = "1.0.5"
6 changes: 6 additions & 0 deletions docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ cross build --target x86_64-pc-windows-gnu
cross build --release --target x86_64-pc-windows-gnu
```

## Testing

``` bash
cargo test
```

## Benchmark

### Flamegraph
Expand Down
6 changes: 3 additions & 3 deletions src/action/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::cli::input;
use crate::context;
use crate::git;
use crate::out;
use crate::repository::CopyOptions;
use crate::repository::{CopyOptions};
use crate::template::renderer;
use crate::utils;

Expand All @@ -29,7 +29,7 @@ impl Action {
out::info::initiate_workspace();

// Check if repositories exist
if self.config.get_repositories().len() <= 0 {
if self.config.get_repository_names().len() <= 0 {
out::error::no_repositories();
exit(1);
}
Expand Down Expand Up @@ -61,7 +61,7 @@ impl Action {
// Check if templates exist
let templates = repository.get_template_names();
if templates.len() <= 0 {
out::error::no_templates(&repository.config.name);
out::error::no_templates(&repository.get_config().name);
exit(1);
}

Expand Down
14 changes: 11 additions & 3 deletions src/action/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ use crate::cli::input;
use crate::config::Config;
use crate::error::RunError;
use crate::repository::Repository;
use crate::repository::custom_repository::CustomRepository;
use crate::repository::default_repository::DefaultRepository;

pub struct Action {
config: Config,
Expand All @@ -21,17 +23,23 @@ impl Action {
}

/// Validat given repository name or open a new selection
fn get_repository(&self, repository_name: Option<&str>) -> Result<Repository, RunError> {
fn get_repository(&self, repository_name: Option<&str>) -> Result<Box<dyn Repository>, RunError> {
// Get repository name from user input
let repository_name = if repository_name.is_none() {
let repositories = self.config.get_repositories();
let repositories = self.config.get_repository_names();
input::select("repository", &repositories)?
} else {
String::from(repository_name.unwrap())
};

// Load repository
let repository = Repository::new(&self.config, &repository_name)?;
let repository: Box<dyn Repository> = if repository_name == "templates" {
let repository = DefaultRepository::new(&self.config)?;
Box::new(repository)
} else {
let repository = CustomRepository::new(&self.config, &repository_name)?;
Box::new(repository)
};

Ok(repository)
}
Expand Down
137 changes: 85 additions & 52 deletions src/action/repository/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,90 +5,119 @@ use crate::cli::input;
use crate::config::RepositoryOptions;
use crate::git;
use crate::meta;
use crate::meta::Type;
use crate::out;
use crate::repository;
use crate::repository::custom_repository;
use crate::utils;

use clap::ArgMatches;

impl Action {
pub fn repository_add(&self, args: &ArgMatches) {
let repository_name = args.value_of("repository");
let repository_name = args.value_of("name");
let repository_description = args.value_of("description");
let repository_provider = args.value_of("provider");
let repository_authentication = args.value_of("authentication");
let repository_url = args.value_of("url");
let repository_branch = args.value_of("branch");

let mut git_options = git::Options::new();

// Enable remote
git_options.enabled = true;

// Get provider
git_options.provider = match input::select(
"Provider",
&vec![String::from("github"), String::from("gitlab")],
) {
Ok(value) => {
if value == "github" {
Some(git::Provider::GITHUB)
} else if value == "gitlab" {
Some(git::Provider::GITLAB)
} else {
exit(1);
git_options.provider = if repository_provider.is_none() {
match input::select(
"Provider",
&vec![String::from("github"), String::from("gitlab")],
) {
Ok(value) => match git::Provider::from(&value) {
Ok(provider) => Some(provider),
Err(error) => {
log::error!("{}", error);
eprintln!("{}", error);
exit(1)
}
},
Err(error) => {
log::error!("{}", error);
eprintln!("{}", error);
exit(1)
}
}
Err(error) => {
log::error!("{}", error);
eprintln!("{}", error);
exit(1)
} else {
match git::Provider::from(&repository_provider.unwrap()) {
Ok(provider) => Some(provider),
Err(error) => {
eprintln!("{}", error);
exit(1)
}
}
};

// Get authentication type
git_options.auth = match input::select(
"Auth type",
&vec![
String::from("token"),
String::from("basic"),
String::from("none"),
],
) {
Ok(value) => {
if value == "basic" {
Some(git::AuthType::BASIC)
} else if value == "none" {
Some(git::AuthType::NONE)
} else if value == "token" {
Some(git::AuthType::TOKEN)
} else {
git_options.auth = if repository_authentication.is_none() {
match input::select(
"Auth type",
&vec![
String::from("token"),
String::from("basic"),
String::from("none"),
],
) {
Ok(value) => match git::AuthType::from(&value) {
Ok(auth_type) => Some(auth_type),
Err(error) => {
log::error!("{}", error);
eprintln!("{}", error);
exit(1)
}
},
Err(error) => {
log::error!("{}", error);
eprintln!("{}", error);
exit(1)
}
}
Err(error) => {
log::error!("{}", error);
eprintln!("{}", error);
exit(1)
} else {
match git::AuthType::from(&repository_authentication.unwrap()) {
Ok(auth_type) => Some(auth_type),
Err(error) => {
log::error!("{}", error);
eprintln!("{}", error);
exit(1)
}
}
};

// Get repository remote url
git_options.url = match input::text("Enter remote repository url", false) {
Ok(value) => Some(value),
Err(error) => {
log::error!("{}", error);
eprintln!("{}", error);
exit(1);
git_options.url = if repository_url.is_none() {
match input::text("Enter remote repository url", false) {
Ok(value) => Some(value),
Err(error) => {
log::error!("{}", error);
eprintln!("{}", error);
exit(1);
}
}
} else {
Some(String::from(repository_url.unwrap()))
};

// Get branch
git_options.branch =
git_options.branch = if repository_branch.is_none() {
match input::text_with_default("Enter remote branch", "master") {
Ok(value) => Some(value),
Err(error) => {
log::error!("{}", error);
eprintln!("{}", error);
exit(1);
}
};
}
} else {
Some(String::from(repository_branch.unwrap()))
};

// Get credentials for different auth types
match git_options.auth.clone().unwrap() {
Expand Down Expand Up @@ -144,12 +173,16 @@ impl Action {
}
};

// Check for meta type repository
if meta.kind != Type::REPOSITORY {
log::error!("{}", format!("Wrong type: {}", meta.kind));
eprintln!("{}", format!("Wrong type: {}", meta.kind));
exit(1)
}

// Get repository name from user input
let repository_name = if repository_name.is_none() {
match input::text_with_default(
"Enter repository name",
&meta.name,
) {
match input::text_with_default("Enter repository name", &meta.name) {
Ok(value) => value,
Err(error) => {
log::error!("{}", error);
Expand All @@ -162,7 +195,7 @@ impl Action {
};

// Validate name
let repositories = self.config.get_repositories();
let repositories = self.config.get_repository_names();
if repositories.contains(&repository_name) {
out::error::repository_exists(&repository_name);
exit(1);
Expand Down Expand Up @@ -190,10 +223,10 @@ impl Action {
};

let mut new_config = self.config.clone();
new_config.template_repositories.push(options.clone());
new_config.repositories.push(options.clone());

// Add repository
match repository::add(&new_config, &options) {
match custom_repository::add(&new_config, &options) {
Ok(repository) => repository,
Err(error) => {
log::error!("{}", error);
Expand Down
Loading

0 comments on commit d0982a2

Please sign in to comment.