Skip to content

Commit 4c812ba

Browse files
committed
feat: v0.1.8
1 parent 8683038 commit 4c812ba

27 files changed

Lines changed: 1320 additions & 6 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
/tmp
12
/target
23
Cargo.lock

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "hyperlane-cli"
3-
version = "0.1.7"
3+
version = "0.1.8"
44
readme = "README.md"
55
edition = "2024"
66
authors = ["root@ltpp.vip"]
@@ -9,7 +9,7 @@ description = """A command-line tool for Hyperlane framework."""
99
keywords = ["output", "console", "log", "print", "color"]
1010
repository = "https://github.com/hyperlane-dev/hyperlane-cli"
1111
categories = ["command-line-interface", "development-tools", "visualization"]
12-
exclude = ["target", "Cargo.lock", "sh", ".github"]
12+
exclude = ["target", "Cargo.lock", "sh", ".github", "tmp"]
1313

1414
[dependencies]
1515
toml = "0.9.8"

src/bump/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,7 @@ mod r#enum;
22
mod r#fn;
33
mod r#struct;
44

5+
#[cfg(test)]
6+
mod test;
7+
58
pub(crate) use {r#enum::*, r#fn::*, r#struct::*};

src/bump/test.rs

Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
use crate::*;
2+
3+
#[test]
4+
fn test_bump_version_type_enum() {
5+
assert_eq!(BumpVersionType::Patch, BumpVersionType::Patch);
6+
assert_eq!(BumpVersionType::Minor, BumpVersionType::Minor);
7+
assert_eq!(BumpVersionType::Major, BumpVersionType::Major);
8+
assert_eq!(BumpVersionType::Release, BumpVersionType::Release);
9+
assert_eq!(BumpVersionType::Alpha, BumpVersionType::Alpha);
10+
assert_eq!(BumpVersionType::Beta, BumpVersionType::Beta);
11+
assert_eq!(BumpVersionType::Rc, BumpVersionType::Rc);
12+
}
13+
14+
#[test]
15+
fn test_version_struct_creation() {
16+
let version: Version = Version {
17+
major: 1,
18+
minor: 2,
19+
patch: 3,
20+
prerelease: Some("alpha.1".to_string()),
21+
};
22+
assert_eq!(version.major, 1);
23+
assert_eq!(version.minor, 2);
24+
assert_eq!(version.patch, 3);
25+
assert_eq!(version.prerelease, Some("alpha.1".to_string()));
26+
}
27+
28+
#[test]
29+
fn test_version_clone() {
30+
let version: Version = Version {
31+
major: 1,
32+
minor: 2,
33+
patch: 3,
34+
prerelease: Some("beta".to_string()),
35+
};
36+
let cloned: Version = version.clone();
37+
assert_eq!(cloned.major, version.major);
38+
assert_eq!(cloned.minor, version.minor);
39+
assert_eq!(cloned.patch, version.patch);
40+
assert_eq!(cloned.prerelease, version.prerelease);
41+
}
42+
43+
#[test]
44+
fn test_execute_bump_integration() {
45+
use std::fs::write;
46+
use std::path::PathBuf;
47+
let tmp_dir: PathBuf = PathBuf::from("./tmp/test_bump");
48+
let _ = std::fs::create_dir_all(&tmp_dir);
49+
let manifest_path: PathBuf = tmp_dir.join("Cargo.toml");
50+
let content: &str = r#"[package]
51+
name = "test-package"
52+
version = "0.1.0"
53+
edition = "2024"
54+
"#;
55+
write(&manifest_path, content).unwrap();
56+
let result: Result<String, Box<dyn std::error::Error>> =
57+
execute_bump(manifest_path.to_str().unwrap(), &BumpVersionType::Patch);
58+
assert!(result.is_ok());
59+
assert_eq!(result.unwrap(), "0.1.1");
60+
let updated_content: String = std::fs::read_to_string(&manifest_path).unwrap();
61+
assert!(updated_content.contains("version = \"0.1.1\""));
62+
}
63+
64+
#[test]
65+
fn test_execute_bump_minor() {
66+
use std::fs::write;
67+
use std::path::PathBuf;
68+
let tmp_dir: PathBuf = PathBuf::from("./tmp/test_bump_minor");
69+
let _ = std::fs::create_dir_all(&tmp_dir);
70+
let manifest_path: PathBuf = tmp_dir.join("Cargo.toml");
71+
let content: &str = r#"[package]
72+
name = "test-package"
73+
version = "0.1.0"
74+
edition = "2024"
75+
"#;
76+
write(&manifest_path, content).unwrap();
77+
let result: Result<String, Box<dyn std::error::Error>> =
78+
execute_bump(manifest_path.to_str().unwrap(), &BumpVersionType::Minor);
79+
assert!(result.is_ok());
80+
assert_eq!(result.unwrap(), "0.2.0");
81+
}
82+
83+
#[test]
84+
fn test_execute_bump_major() {
85+
use std::fs::write;
86+
use std::path::PathBuf;
87+
let tmp_dir: PathBuf = PathBuf::from("./tmp/test_bump_major");
88+
let _ = std::fs::create_dir_all(&tmp_dir);
89+
let manifest_path: PathBuf = tmp_dir.join("Cargo.toml");
90+
let content: &str = r#"[package]
91+
name = "test-package"
92+
version = "0.1.0"
93+
edition = "2024"
94+
"#;
95+
write(&manifest_path, content).unwrap();
96+
let result: Result<String, Box<dyn std::error::Error>> =
97+
execute_bump(manifest_path.to_str().unwrap(), &BumpVersionType::Major);
98+
assert!(result.is_ok());
99+
assert_eq!(result.unwrap(), "1.0.0");
100+
}
101+
102+
#[test]
103+
fn test_execute_bump_alpha() {
104+
use std::fs::write;
105+
use std::path::PathBuf;
106+
let tmp_dir: PathBuf = PathBuf::from("./tmp/test_bump_alpha");
107+
let _ = std::fs::create_dir_all(&tmp_dir);
108+
let manifest_path: PathBuf = tmp_dir.join("Cargo.toml");
109+
let content: &str = r#"[package]
110+
name = "test-package"
111+
version = "0.1.0"
112+
edition = "2024"
113+
"#;
114+
write(&manifest_path, content).unwrap();
115+
let result: Result<String, Box<dyn std::error::Error>> =
116+
execute_bump(manifest_path.to_str().unwrap(), &BumpVersionType::Alpha);
117+
assert!(result.is_ok());
118+
assert_eq!(result.unwrap(), "0.1.0-alpha");
119+
}
120+
121+
#[test]
122+
fn test_execute_bump_beta() {
123+
use std::fs::write;
124+
use std::path::PathBuf;
125+
let tmp_dir: PathBuf = PathBuf::from("./tmp/test_bump_beta");
126+
let _ = std::fs::create_dir_all(&tmp_dir);
127+
let manifest_path: PathBuf = tmp_dir.join("Cargo.toml");
128+
let content: &str = r#"[package]
129+
name = "test-package"
130+
version = "0.1.0-alpha.2"
131+
edition = "2024"
132+
"#;
133+
write(&manifest_path, content).unwrap();
134+
let result: Result<String, Box<dyn std::error::Error>> =
135+
execute_bump(manifest_path.to_str().unwrap(), &BumpVersionType::Beta);
136+
assert!(result.is_ok());
137+
assert_eq!(result.unwrap(), "0.1.0-beta.1");
138+
}
139+
140+
#[test]
141+
fn test_execute_bump_rc() {
142+
use std::fs::write;
143+
use std::path::PathBuf;
144+
let tmp_dir: PathBuf = PathBuf::from("./tmp/test_bump_rc");
145+
let _ = std::fs::create_dir_all(&tmp_dir);
146+
let manifest_path: PathBuf = tmp_dir.join("Cargo.toml");
147+
let content: &str = r#"[package]
148+
name = "test-package"
149+
version = "0.1.0-beta.1"
150+
edition = "2024"
151+
"#;
152+
write(&manifest_path, content).unwrap();
153+
let result: Result<String, Box<dyn std::error::Error>> =
154+
execute_bump(manifest_path.to_str().unwrap(), &BumpVersionType::Rc);
155+
assert!(result.is_ok());
156+
assert_eq!(result.unwrap(), "0.1.0-rc.1");
157+
}
158+
159+
#[test]
160+
fn test_execute_bump_release() {
161+
use std::fs::write;
162+
use std::path::PathBuf;
163+
let tmp_dir: PathBuf = PathBuf::from("./tmp/test_bump_release");
164+
let _ = std::fs::create_dir_all(&tmp_dir);
165+
let manifest_path: PathBuf = tmp_dir.join("Cargo.toml");
166+
let content: &str = r#"[package]
167+
name = "test-package"
168+
version = "0.1.0-alpha"
169+
edition = "2024"
170+
"#;
171+
write(&manifest_path, content).unwrap();
172+
let result: Result<String, Box<dyn std::error::Error>> =
173+
execute_bump(manifest_path.to_str().unwrap(), &BumpVersionType::Release);
174+
assert!(result.is_ok());
175+
assert_eq!(result.unwrap(), "0.1.0");
176+
}
177+
178+
#[test]
179+
fn test_execute_bump_no_version_field() {
180+
use std::fs::write;
181+
use std::path::PathBuf;
182+
let tmp_dir: PathBuf = PathBuf::from("./tmp/test_bump_no_version");
183+
let _ = std::fs::create_dir_all(&tmp_dir);
184+
let manifest_path: PathBuf = tmp_dir.join("Cargo.toml");
185+
let content: &str = r#"[package]
186+
name = "test-package"
187+
edition = "2024"
188+
"#;
189+
write(&manifest_path, content).unwrap();
190+
let result: Result<String, Box<dyn std::error::Error>> =
191+
execute_bump(manifest_path.to_str().unwrap(), &BumpVersionType::Patch);
192+
assert!(result.is_err());
193+
}

src/command/enum.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ pub(crate) enum CommandType {
1111
Publish,
1212
/// Create a new project from template
1313
New,
14+
/// Generate template components
15+
Template,
1416
/// Show help
1517
Help,
1618
/// Show version

src/config/fn.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::str::FromStr;
2+
13
use crate::*;
24

35
/// Parse command line arguments
@@ -13,6 +15,9 @@ pub(crate) fn parse_args() -> Args {
1315
let mut bump_type: Option<BumpVersionType> = None;
1416
let mut max_retries: u32 = 3;
1517
let mut project_name: Option<String> = None;
18+
let mut template_type: Option<TemplateType> = None;
19+
let mut model_sub_type: Option<ModelSubType> = None;
20+
let mut component_name: Option<String> = None;
1621
let mut i: usize = 1;
1722
while i < raw_args.len() {
1823
let arg: &str = raw_args[i].as_str();
@@ -57,6 +62,37 @@ pub(crate) fn parse_args() -> Args {
5762
}
5863
}
5964
}
65+
"template" => {
66+
if command == CommandType::Help || command == CommandType::Version {
67+
command = CommandType::Template;
68+
i += 1;
69+
if i < raw_args.len()
70+
&& !raw_args[i].starts_with("--")
71+
&& !raw_args[i].starts_with("-")
72+
{
73+
let type_str: &str = &raw_args[i];
74+
template_type = TemplateType::from_str(type_str).ok();
75+
i += 1;
76+
if template_type == Some(TemplateType::Model)
77+
&& i < raw_args.len()
78+
&& !raw_args[i].starts_with("--")
79+
&& !raw_args[i].starts_with("-")
80+
{
81+
let sub_type_str: &str = &raw_args[i];
82+
model_sub_type = ModelSubType::from_str(sub_type_str).ok();
83+
i += 1;
84+
}
85+
if i < raw_args.len()
86+
&& !raw_args[i].starts_with("--")
87+
&& !raw_args[i].starts_with("-")
88+
{
89+
component_name = Some(raw_args[i].clone());
90+
i += 1;
91+
}
92+
i -= 1;
93+
}
94+
}
95+
}
6096
"--patch" => {
6197
bump_type = Some(BumpVersionType::Patch);
6298
}
@@ -106,5 +142,8 @@ pub(crate) fn parse_args() -> Args {
106142
bump_type,
107143
max_retries,
108144
project_name,
145+
template_type,
146+
model_sub_type,
147+
component_name,
109148
}
110149
}

src/config/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
mod r#fn;
22
mod r#struct;
33

4+
#[cfg(test)]
5+
mod test;
6+
47
pub(crate) use {r#fn::*, r#struct::*};

src/config/struct.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,10 @@ pub struct Args {
1515
pub max_retries: u32,
1616
/// Project name for new command
1717
pub project_name: Option<String>,
18+
/// Template type for template command
19+
pub template_type: Option<TemplateType>,
20+
/// Model subtype for template command (only when template_type is Model)
21+
pub model_sub_type: Option<ModelSubType>,
22+
/// Component name for template command
23+
pub component_name: Option<String>,
1824
}

0 commit comments

Comments
 (0)