Skip to content

Commit

Permalink
Merge pull request #28 from perryrh0dan/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
perryrh0dan authored Aug 31, 2020
2 parents 89b1adc + 95c51b7 commit 3414a3d
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 77 deletions.
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
@@ -1,6 +1,6 @@
[package]
name = "tmpo"
version = "1.2.0"
version = "1.2.2"
authors = ["Thomas Pöhlmann <thomaspoehlmann96@googlemail.com>"]
edition = "2018"

Expand Down
75 changes: 11 additions & 64 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,37 +70,29 @@ Come over to [Twitter](https://twitter.com/perryrh0dan1) to share your thoughts

## Usage

### Cli
### CLI

``` bash
tmpo init example --repository default --template typescript --directory .
tmpo init example --repository default --template typescript --directory . --remote https://github.com/perryrh0dan/2fa
```

### Repositories

A repository is a folder that contains up to n different templates. A repository can be connected with a remote git repository. Templates are then automaticly synced. Repositories are located in the 'template_dir'.
A repository is a folder that contains up to n different templates. A repository can be connected with a remote git repository. Templates are then automaticly synced. Repositories are located in the 'template_dir'.

### Templates

Templates can be configured with a `meta.json` in the template root. The official template repository with detailed instructions can be found [here](https://github.com/perryrh0dan/templates).

#### Format
To add a new repository use the `repository subcommand` and follow the instructions on the screen.

``` json
{
"name": "",
"extend": [""],
"exclude": [""],
"scripts": {
"before_install": "",
"after_install": ""
}
}
``` bash
tmpo repository add
```

For a detailed description how to create and maintain templates have a look at the default tempaltes [repository](https://github.com/perryrh0dan/templates)
### Templates

Templates can be configured with a `meta.json` in the template root.
For a detailed description how to create and maintain templates have a look at the instructions and default templates [repository](https://github.com/perryrh0dan/templates)

## Configuration
The configuration file should only be changed by experienced users.

To configure tmpo navigate to the ~/.tmpo/config.yaml file and modify any of the options to match your own preference. To reset back to the default values, simply delete the config file from your home directory.

Expand All @@ -120,51 +112,6 @@ The following illustrates all the available options with their respective defaul
password: ~
```
### In Detail
#### templates_dir
- Type: String
- Default: $HOME/.tmpo/templates
Filesystem path where all the templates are stored.
#### templates_repo
- Type: String
- Default: $HOME/.tmpo/templates
##### url
- Type: String
- Default: $HOME/.tmpo/templates
Url of the repository where templates are managed.
##### auth
- Type: String
- Default: none
- Values: `none`, `token`

##### token
- Type: String
- Default: none

Access token is only used when auth type is token

##### username
- Type: String
- Default: none

Coming soon

##### password
- Type: String
- Default: none

##### privatekey

Coming soon

#####

## Development
### Build
Expand Down
14 changes: 7 additions & 7 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ extern crate serde_yaml;

#[derive(serde::Serialize, serde::Deserialize, Debug)]
pub struct Config {
pub templates_dir: String,
pub templates_repositories: Vec<RepositoryOptions>,
pub template_dir: String,
pub template_repositories: Vec<RepositoryOptions>,
}

#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
Expand All @@ -28,15 +28,15 @@ impl Config {
pub fn get_repositories(&self) -> Vec<String> {
let mut repositories = Vec::<String>::new();

for entry in self.templates_repositories.iter() {
for entry in self.template_repositories.iter() {
repositories.push(String::from(&entry.name));
}

return repositories;
}

pub fn get_repository_config(&self, name: &str) -> Option<RepositoryOptions> {
let config = self.templates_repositories.iter().find(|&x| utils::lowercase(&x.name) == utils::lowercase(&name));
let config = self.template_repositories.iter().find(|&x| utils::lowercase(&x.name) == utils::lowercase(&name));

if config.is_some() {
return Some(config.unwrap().clone());
Expand All @@ -56,7 +56,7 @@ pub fn init() -> Result<Config, Error> {

let config = load_config()?;

ensure_template_dir(&config.templates_dir)?;
ensure_template_dir(&config.template_dir)?;

Ok(config)
}
Expand Down Expand Up @@ -143,8 +143,8 @@ fn get_default_config() -> Config {
});

let config = Config {
templates_dir: template_dir,
templates_repositories: repo_options,
template_dir: template_dir,
template_repositories: repo_options,
};

return config;
Expand Down
8 changes: 4 additions & 4 deletions src/repository/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl Repository {
Option::None => return Err(RepositoryError::NotFound),
};

let directory = String::from(&config.templates_dir) + "/" + &utils::lowercase(name);
let directory = String::from(&config.template_dir) + "/" + &utils::lowercase(name);

let mut repository = Repository {
directory: directory,
Expand All @@ -52,7 +52,7 @@ impl Repository {
}

pub fn delete_repository(config: &Config, name: &str) -> Result<(), Error> {
let mut repository_dir = PathBuf::from(&config.templates_dir);
let mut repository_dir = PathBuf::from(&config.template_dir);
repository_dir.push(&utils::lowercase(name));

log::info!("Delete repository directory {}", &repository_dir.to_owned().to_str().unwrap());
Expand Down Expand Up @@ -114,7 +114,7 @@ impl Repository {
}

fn ensure_repository_dir(&self, config: &Config) -> Result<(), Error> {
let mut directory = PathBuf::from(&config.templates_dir);
let mut directory = PathBuf::from(&config.template_dir);
directory.push(&utils::lowercase(&self.config.name));
let r = fs::create_dir_all(&directory);
match r {
Expand All @@ -131,7 +131,7 @@ impl Repository {
git::GitError::AddRemoteError => println!("Add Remote Error"),
},
};

match git::update(&directory, &self.config.git_options) {
Ok(()) => (),
Err(_e) => out::error::update_templates(),
Expand Down

0 comments on commit 3414a3d

Please sign in to comment.