Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ categories = ["network-programming", "web-programming"]
exclude.workspace = true

[workspace.package]
version = "21.10.0"
version = "21.11.0"
readme = "README.md"
edition = "2024"
authors = ["root@ltpp.vip"]
Expand All @@ -25,15 +25,15 @@ resolver = "2"
members = ["compress", "constant", "type", "request", "core", "macros", "cli", "plugin/websocket"]

[workspace.dependencies]
hyperlane = { path = ".", version = "21.10.0" }
http-type = { path = "type", version = "21.10.0" }
hyperlane-cli = { path = "cli", version = "21.10.0" }
hyperlane-core = { path = "core", version = "21.10.0" }
http-request = { path = "request", version = "21.10.0" }
http-compress = { path = "compress", version = "21.10.0" }
http-constant = { path = "constant", version = "21.10.0" }
hyperlane-macros = { path = "macros", version = "21.10.0" }
hyperlane-plugin-websocket = { path = "plugin/websocket", version = "21.10.0" }
hyperlane = { path = ".", version = "21.11.0" }
http-type = { path = "type", version = "21.11.0" }
hyperlane-cli = { path = "cli", version = "21.11.0" }
hyperlane-core = { path = "core", version = "21.11.0" }
http-request = { path = "request", version = "21.11.0" }
http-compress = { path = "compress", version = "21.11.0" }
http-constant = { path = "constant", version = "21.11.0" }
hyperlane-macros = { path = "macros", version = "21.11.0" }
hyperlane-plugin-websocket = { path = "plugin/websocket", version = "21.11.0" }

hex = "0.4.3"
md5 = "0.8.1"
Expand Down
11 changes: 11 additions & 0 deletions cli/src/config/const.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/// Long form of the help flag.
pub(crate) const FLAG_LONG_HELP: &str = "--help";

/// Long form of the version flag.
pub(crate) const FLAG_LONG_VERSION: &str = "--version";

/// Sub-command that starts the file watcher.
pub(crate) const COMMAND_WATCH: &str = "watch";

/// Sub-command that scaffolds a component from a template.
pub(crate) const COMMAND_TEMPLATE: &str = "template";
10 changes: 6 additions & 4 deletions cli/src/config/fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ pub fn parse_args() -> Args {
while i < raw_args.len() {
let arg: &str = raw_args[i].as_str();
match arg {
"-h" | "--help" => {
"-h" | FLAG_LONG_HELP => {
command = CommandType::Help;
}
"-v" | "--version" => {
"-v" | FLAG_LONG_VERSION => {
command = CommandType::Version;
}
"watch" if (command == CommandType::Help || command == CommandType::Version) => {
COMMAND_WATCH if (command == CommandType::Help || command == CommandType::Version) => {
command = CommandType::Watch;
}
"new" if (command == CommandType::Help || command == CommandType::Version) => {
Expand All @@ -37,7 +37,9 @@ pub fn parse_args() -> Args {
i -= 1;
}
}
"template" if (command == CommandType::Help || command == CommandType::Version) => {
COMMAND_TEMPLATE
if (command == CommandType::Help || command == CommandType::Version) =>
{
command = CommandType::Template;
i += 1;
if i < raw_args.len()
Expand Down
3 changes: 3 additions & 0 deletions cli/src/config/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
mod r#const;
mod r#fn;
mod r#struct;

pub use {r#fn::*, r#struct::*};

pub(crate) use r#const::*;

use super::*;
4 changes: 3 additions & 1 deletion cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ pub use {command::*, config::*, help::*, logger::*, new::*, template::*, version

pub(crate) use std::{
env::args,
fmt::Arguments,
io,
path::{Path, PathBuf},
process::Stdio,
process::{Output, Stdio},
str::FromStr,
};

pub(crate) use {
log::SetLoggerError,
lombok_macros::*,
notify::{Event, EventKind, RecommendedWatcher, RecursiveMode, Watcher, recommended_watcher},
std::ffi::OsStr,
Expand Down
4 changes: 2 additions & 2 deletions cli/src/logger/impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl log::Log for Logger {
}
let now_time: String = color_output::time();
let level: log::Level = record.level();
let args: &std::fmt::Arguments<'_> = record.args();
let args: &Arguments<'_> = record.args();
let file: Option<&str> = record.file();
let module_path: Option<&str> = record.module_path();
let target: &str = record.target();
Expand Down Expand Up @@ -88,7 +88,7 @@ impl Logger {
///
/// # Arguments
///
/// - `LevelFilter` - The maximum log level to enable.
/// - `log::LevelFilter` - The maximum log level to enable.
pub fn init(level_filter: log::LevelFilter) {
let _: Result<(), SetLoggerError> = log::set_logger(&LOGGER);
log::set_max_level(level_filter);
Expand Down
2 changes: 0 additions & 2 deletions cli/src/logger/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,4 @@ pub use {::log, color_output::*};

pub(crate) use {r#const::*, r#static::*};

pub(crate) use log::SetLoggerError;

use super::*;
1 change: 1 addition & 0 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use hyperlane_cli::*;

use std::process::exit;

/// Parses the command line arguments and dispatches the selected sub-command.
#[tokio::main]
async fn main() {
Logger::init(log::LevelFilter::Info);
Expand Down
20 changes: 20 additions & 0 deletions cli/src/new/const.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/// Message reported when the project name is empty.
pub(crate) const ERROR_PROJECT_NAME_EMPTY: &str = "Project name cannot be empty";

/// Message reported when the project name holds a path separator or a colon.
pub(crate) const ERROR_PROJECT_NAME_INVALID_CHARACTERS: &str =
"Project name contains invalid characters";

/// Message reported when the project name starts with a dot or a dash.
pub(crate) const ERROR_PROJECT_NAME_INVALID_PREFIX: &str =
"Project name cannot start with '.' or '-'";

/// Repository cloned by the `new` command when no template is configured.
pub(crate) const DEFAULT_TEMPLATE_URL: &str =
"https://github.com/hyperlane-dev/hyperlane-quick-start";

/// Flag used to probe whether git is installed.
pub(crate) const GIT_FLAG_VERSION: &str = "--version";

/// Git sub-command that clones the template repository.
pub(crate) const GIT_SUBCOMMAND_CLONE: &str = "clone";
18 changes: 8 additions & 10 deletions cli/src/new/fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,16 @@ use super::*;
/// - `Result<(), NewError>` - Ok if valid, error otherwise
fn validate_project_name(name: &str) -> Result<(), NewError> {
if name.is_empty() {
return Err(NewError::InvalidName(
"Project name cannot be empty".to_string(),
));
return Err(NewError::InvalidName(ERROR_PROJECT_NAME_EMPTY.to_string()));
}
if name.contains('/') || name.contains('\\') || name.contains(':') {
return Err(NewError::InvalidName(
"Project name contains invalid characters".to_string(),
ERROR_PROJECT_NAME_INVALID_CHARACTERS.to_string(),
));
}
if name.starts_with('.') || name.starts_with('-') {
return Err(NewError::InvalidName(
"Project name cannot start with '.' or '-'".to_string(),
ERROR_PROJECT_NAME_INVALID_PREFIX.to_string(),
));
}
Ok(())
Expand All @@ -34,13 +32,13 @@ fn validate_project_name(name: &str) -> Result<(), NewError> {
///
/// - `Result<(), NewError>` - Ok if git is available, error otherwise
async fn check_git_available() -> Result<(), NewError> {
let output: std::process::Output = Command::new("git")
.arg("--version")
let output: Output = Command::new("git")
.arg(GIT_FLAG_VERSION)
.stdout(Stdio::null())
.stderr(Stdio::null())
.output()
.await
.map_err(|_: std::io::Error| NewError::GitNotFound)?;
.map_err(|_: io::Error| NewError::GitNotFound)?;
if output.status.success() {
Ok(())
} else {
Expand All @@ -62,8 +60,8 @@ async fn git_clone(config: &NewProjectConfig) -> Result<(), NewError> {
if project_path.exists() {
return Err(NewError::ProjectExists(config.project_name.clone()));
}
let output: std::process::Output = Command::new("git")
.arg("clone")
let output: Output = Command::new("git")
.arg(GIT_SUBCOMMAND_CLONE)
.arg(&config.template_url)
.arg(&config.project_name)
.stdout(Stdio::piped())
Expand Down
2 changes: 1 addition & 1 deletion cli/src/new/impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ impl NewProjectConfig {
pub fn new(project_name: String) -> Self {
Self {
project_name,
template_url: "https://github.com/hyperlane-dev/hyperlane-quick-start".to_string(),
template_url: DEFAULT_TEMPLATE_URL.to_string(),
}
}
}
3 changes: 3 additions & 0 deletions cli/src/new/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
mod r#const;
mod r#enum;
mod r#fn;
mod r#impl;
mod r#struct;

pub use {r#enum::*, r#fn::*, r#struct::*};

pub(crate) use r#const::*;

use super::*;
89 changes: 89 additions & 0 deletions cli/src/template/const.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/// Lowercase name of the `Controller` template type and its directory.
pub(crate) const TEMPLATE_TYPE_CONTROLLER: &str = "controller";

/// Lowercase name of the `Domain` template type and its directory.
pub(crate) const TEMPLATE_TYPE_DOMAIN: &str = "domain";

/// Lowercase name of the `Exception` template type and its directory.
pub(crate) const TEMPLATE_TYPE_EXCEPTION: &str = "exception";

/// Lowercase name of the `Mapper` template type and its directory.
pub(crate) const TEMPLATE_TYPE_MAPPER: &str = "mapper";

/// Lowercase name of the `Model` template type and its directory.
pub(crate) const TEMPLATE_TYPE_MODEL: &str = "model";

/// Lowercase name of the `Repository` template type and its directory.
pub(crate) const TEMPLATE_TYPE_REPOSITORY: &str = "repository";

/// Lowercase name of the `Service` template type and its directory.
pub(crate) const TEMPLATE_TYPE_SERVICE: &str = "service";

/// Lowercase name of the `Utils` template type and its directory.
pub(crate) const TEMPLATE_TYPE_UTILS: &str = "utils";

/// Lowercase name of the `View` template type and its directory.
pub(crate) const TEMPLATE_TYPE_VIEW: &str = "view";

/// Lowercase name of the `Application` model sub type and its directory.
pub(crate) const MODEL_SUB_TYPE_APPLICATION: &str = "application";

/// Lowercase name of the `Request` model sub type and its directory.
pub(crate) const MODEL_SUB_TYPE_REQUEST: &str = "request";

/// Lowercase name of the `Response` model sub type and its directory.
pub(crate) const MODEL_SUB_TYPE_RESPONSE: &str = "response";

/// Directory that holds every generated component tree.
pub(crate) const TEMPLATE_CONFIG_BASE_DIRECTORY: &str = "./application";

/// Keyword file name of the `const` module inside a generated directory.
pub(crate) const MODULE_NAME_CONST: &str = "const";

/// Keyword file name of the `enum` module inside a generated directory.
pub(crate) const MODULE_NAME_ENUM: &str = "enum";

/// Keyword file name of the `fn` module inside a generated directory.
pub(crate) const MODULE_NAME_FN: &str = "fn";

/// Keyword file name of the `impl` module inside a generated directory.
pub(crate) const MODULE_NAME_IMPL: &str = "impl";

/// Keyword file name of the `static` module inside a generated directory.
pub(crate) const MODULE_NAME_STATIC: &str = "static";

/// Keyword file name of the `struct` module inside a generated directory.
pub(crate) const MODULE_NAME_STRUCT: &str = "struct";

/// File name of the generated module declaration file.
pub(crate) const FILE_NAME_MOD_RS: &str = "mod.rs";

/// File name of the generated `const` file.
pub(crate) const FILE_NAME_CONST_RS: &str = "const.rs";

/// File name of the generated `enum` file.
pub(crate) const FILE_NAME_ENUM_RS: &str = "enum.rs";

/// File name of the generated `fn` file.
pub(crate) const FILE_NAME_FN_RS: &str = "fn.rs";

/// File name of the generated `impl` file.
pub(crate) const FILE_NAME_IMPL_RS: &str = "impl.rs";

/// File name of the generated `static` file.
pub(crate) const FILE_NAME_STATIC_RS: &str = "static.rs";

/// File name of the generated `struct` file.
pub(crate) const FILE_NAME_STRUCT_RS: &str = "struct.rs";

/// Opening delimiter of the aggregated `pub use` line in a generated `mod.rs`.
pub(crate) const PUB_USE_PREFIX: &str = "pub use {";

/// First line written into every generated keyword file.
pub(crate) const KEYWORD_FILE_HEADER: &str = "use super::*;\n";

/// Message reported when a model template is requested without a sub type.
pub(crate) const ERROR_MISSING_MODEL_SUB_TYPE: &str = "Missing model subtype";

/// Program used to format the freshly generated template code.
pub(crate) const CARGO_FMT_PROGRAM: &str = "cargo";
Loading
Loading