Skip to content

Commit

Permalink
v0.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
cophilot committed Feb 6, 2024
1 parent 6836741 commit 453a891
Show file tree
Hide file tree
Showing 11 changed files with 110 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .phil-project
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
logo:assets/logo.png
logo_small:assets/logo.png
description_translate:de
version:0.2.2
version:0.3.0
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

---

## [v0.3.0](https://github.com/cophilot/templify/tree/0.3.0) (2024-2-6)

- Bug fixes
- Added `command` argument for the `help` command to display help for a specific command
- Command `generate` uses pattern matching to determine the type of template to generate
- Added `-strict` flag for `generate` command to disable pattern matching

---

## [v0.2.2](https://github.com/cophilot/templify/tree/0.2.2) (2024-2-5)

- Added `-force` flag for `load` command
Expand Down
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 = "templify"
version = "0.2.2"
version = "0.3.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
15 changes: 12 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,20 @@
<a href="https://github.com/cophilot/templify/commits/main">
<img src="https://img.shields.io/github/last-commit/cophilot/templify" alt="last commit" />
</a>
<a href="https://templify.philipp-bonin.com/">
<img src="https://img.shields.io/badge/docs-visit-yellow" alt="docs" />
</a>
<a href="https://github.com/cophilot/templify/stargazers">
<img src="https://img.shields.io/github/stars/cophilot/templify" alt="stars" />
</a>
</div>

---

For a more detailed documentation visit the [templify-docs](https://templify.philipp-bonin.com/).

---

- [Concept](#concept)
- [Installation](#installation)
- [Linux](#linux)
Expand Down Expand Up @@ -206,10 +213,12 @@ tpy load https://github.com/cophilot/templify-vault/tree/main/React-ts

## [Release Notes](https://github.com/cophilot/templify/blob/master/CHANGELOG.md)

### [v0.2.2](https://github.com/cophilot/templify/tree/0.2.2)
### [v0.3.0](https://github.com/cophilot/templify/tree/0.3.0)

- Added `-force` flag for `load` command
- Added `-version` flag for `update` command
- Bug fixes
- Added `command` argument for the `help` command to display help for a specific command
- Command `generate` uses pattern matching to determine the type of template to generate
- Added `-strict` flag for `generate` command to disable pattern matching

---

Expand Down
4 changes: 4 additions & 0 deletions install
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ do
esac
done

if [[ $version == v* ]]; then
version=${version:1}
fi

echo "Installing templify..."
echo "This will install a binary to $homePath and add it to your PATH."
if [ "$yesFlag" = false ]; then
Expand Down
14 changes: 13 additions & 1 deletion src/command_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,19 @@ pub fn get_all_commands() -> Vec<Command> {

// *** help ***

let help_com = Command::new(
let mut help_com = Command::new(
vec!["help".to_string(), "h".to_string()],
commands::help,
"Show this help message.".to_string(),
);

help_com.add_argument(Argument::new(
"command".to_string(),
0,
false,
"The command to show help for.".to_string(),
));

commands.push(help_com);

// *** version ***
Expand Down Expand Up @@ -138,6 +145,11 @@ pub fn get_all_commands() -> Vec<Command> {
"The name of the new file.".to_string(),
));

generate_com.add_flag(Flag::new_bool_flag(
vec!["strict".to_string()],
"If enabled the template name must match exactly.".to_string(),
));

commands.push(generate_com);

return commands;
Expand Down
62 changes: 55 additions & 7 deletions src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,41 @@ pub fn generate(command: &Command) -> Status {
return st;
}

let template_name = command.get_argument("template-name").value.clone();
let strict = command.get_bool_flag("strict");

let mut template_name = command.get_argument("template-name").value.clone();
let parsed_template_name = template_name.clone().to_lowercase().to_string();
let template_name_raw = template_name.clone().to_string();

let given_name = command.get_argument("new-name").value.clone();

let paths = std::fs::read_dir(".templates").unwrap();
let mut found = false;
for path in paths {
let path = path.unwrap().path();
if path.is_dir() && path.file_name().unwrap().to_str().unwrap() == template_name.to_string()
{
found = true;

let path_name = path
.file_name()
.unwrap()
.to_str()
.unwrap()
.to_string()
.clone();

let parsed_path_name = path_name.clone().to_lowercase().to_string();

if path.is_dir() && parsed_path_name.starts_with(parsed_template_name.as_str()) && !strict {
if found {
return Status::error(format!(
"Template {} is not unique. Please use a more specific name.",
template_name_raw
));
}
template_name = path_name.clone();
found = true;
} else if path.is_dir() && path_name == template_name && strict {
template_name = path_name.clone();
found = true;
break;
}
}
Expand Down Expand Up @@ -202,15 +226,39 @@ pub fn init(command: &Command) -> Status {
return Status::ok();
}

pub fn help(_command: &Command) -> Status {
let command_name = unsafe { crate::env::BASE_COMMAND_NAME.clone() };
pub fn help(command: &Command) -> Status {
let base_command_name = unsafe { crate::env::BASE_COMMAND_NAME.clone() };

if command.get_argument("command").is_set {
let mut command_name = command.get_argument("command").value.clone();
let all_commands = crate::command_storage::get_all_commands();
for c in all_commands {
if c.names.contains(&command_name) {
command_name = c.names[0].clone();
println!("templify help center");
println!("");
println!("<...> - required");
println!("[...] - optional");
println!("");
println!("Usage: {} {}", base_command_name, command_name);
println!("");
println!("{}", c.to_help_string());
println!(
"To get more information please visit: https://templify.philipp-bonin.com/#/command/{}", command_name
);

return Status::ok();
}
}
return Status::error(format!("Command {} not found.", command_name));
}

println!("templify help center");
println!("");
println!("<...> - required");
println!("[...] - optional");
println!("");
println!("Usage: {} <command>", command_name);
println!("Usage: {} <command>", base_command_name);
println!("");
println!("Commands:");

Expand Down
9 changes: 9 additions & 0 deletions src/executer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,22 @@ use crate::command_storage;
pub fn execute(args: Vec<String>) -> bool {
let mut command = command_storage::get_command(&args);
let parse_status = command.parse(&args);
let base_command_name = unsafe { crate::env::BASE_COMMAND_NAME.clone() };

if !parse_status.is_ok {
println!("Command parse error: {}", parse_status.message);
println!("Run `{} help` for more information.", base_command_name);

return false;
}
let execute_status = command.execute();
if !execute_status.is_ok {
println!("Command execution error: {}", execute_status.message);
println!(
"Run `{} help {}` for more information.",
base_command_name, command.names[0]
);

return false;
}
return true;
Expand Down
22 changes: 0 additions & 22 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,29 +30,7 @@ fn main() {
return;
}

// match command
/* match args[1].to_lowercase().as_str() {
"help" => commands::help(),
"-h" => commands::help(),
"version" => commands::version(),
"-v" => commands::version(),
"init" => commands::init(),
"i" => commands::init(),
"new" => commands::new(args),
"n" => commands::new(args),
"list" => commands::list(),
"ls" => commands::list(),
"load" => commands::load(args),
"l" => commands::load(args),
"generate" => commands::generate(args),
"g" => commands::generate(args),
"update" => commands::update(),
_ => println!("Unknown command: {}", args[1]),
} */

if !executer::execute(args) {
let command_name = unsafe { crate::env::BASE_COMMAND_NAME.clone() };
println!("Run `{} help` for more information.", command_name);
std::process::exit(1);
}

Expand Down
5 changes: 5 additions & 0 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ pub fn load_remote_template_file(path: &str, url: &str, force: bool) {

text = text.replace("\\n", "\n");

// create all subdirs if they don't exist
let path_dir = path.split("/").collect::<Vec<&str>>();
let path_dir = path_dir[..path_dir.len() - 1].join("/");
std::fs::create_dir_all(path_dir.clone()).unwrap();

let mut new_file = std::fs::File::create(path).unwrap();
new_file.write_all(text.as_bytes()).unwrap();

Expand Down

0 comments on commit 453a891

Please sign in to comment.