mirror of
https://github.com/dexoron/dcr.git
synced 2026-10-21 11:08:30 +00:00
feat: add --help for all commands, man pages
This commit is contained in:
@@ -19,7 +19,7 @@ use crate::core::config::Config;
|
||||
use crate::core::deps::register;
|
||||
use crate::utils::fs::find_project_root;
|
||||
use crate::utils::log::error;
|
||||
use crate::utils::text::{BOLD_GREEN, colored};
|
||||
use crate::utils::text::{BOLD_CYAN, BOLD_GREEN, colored, printc};
|
||||
use toml::Value;
|
||||
use toml::map::Map;
|
||||
|
||||
@@ -34,6 +34,28 @@ pub struct AddArgs {
|
||||
}
|
||||
|
||||
pub fn add(args: &[String]) -> i32 {
|
||||
if args.first().map_or(false, |a| a == "--help") {
|
||||
printc("USAGE:", BOLD_GREEN);
|
||||
printc(" dcr add <name> <source> [--branch <b>] [--tag <t>] [--rev <r>]", BOLD_CYAN);
|
||||
println!();
|
||||
printc("DESCRIPTION:", BOLD_GREEN);
|
||||
println!(" Adds a dependency to the project.");
|
||||
println!();
|
||||
printc("SOURCES:", BOLD_GREEN);
|
||||
println!(" user/repo GitHub shorthand");
|
||||
println!(" github:user/repo GitHub repository");
|
||||
println!(" gitlab:user/repo GitLab repository");
|
||||
println!(" git:host.com/user/repo Generic git repository");
|
||||
println!(" path:./path/to/lib Local path dependency");
|
||||
println!(" <version> Version from registry");
|
||||
println!();
|
||||
printc("OPTIONS:", BOLD_GREEN);
|
||||
println!(" --branch <b> Use a specific branch");
|
||||
println!(" --tag <t> Use a specific tag");
|
||||
println!(" --rev <r> Use a specific commit hash");
|
||||
return 0;
|
||||
}
|
||||
|
||||
let add_args = match parse_add_args(args) {
|
||||
Ok(a) => a,
|
||||
Err(code) => return code,
|
||||
|
||||
@@ -29,7 +29,7 @@ use crate::utils::build::{
|
||||
};
|
||||
use crate::utils::fs::{check_dir, find_project_root, with_dir};
|
||||
use crate::utils::log::error;
|
||||
use crate::utils::text::{BOLD_GREEN, colored};
|
||||
use crate::utils::text::{BOLD_CYAN, BOLD_GREEN, colored, printc};
|
||||
use glob::glob;
|
||||
use sha2::{Digest, Sha256};
|
||||
use std::fs;
|
||||
@@ -42,6 +42,24 @@ static BUILD_INTERRUPTED: AtomicBool = AtomicBool::new(false);
|
||||
static SIGNAL_HANDLER: Once = Once::new();
|
||||
|
||||
pub fn build(args: &[String]) -> i32 {
|
||||
if args.first().map_or(false, |a| a == "--help") {
|
||||
printc("USAGE:", BOLD_GREEN);
|
||||
printc(" dcr build [--debug | --release] [--target <triple>] [--force] [--clean] [--verbose]", BOLD_CYAN);
|
||||
println!();
|
||||
printc("DESCRIPTION:", BOLD_GREEN);
|
||||
println!(" Compiles the project. Default profile is --debug.");
|
||||
println!();
|
||||
printc("OPTIONS:", BOLD_GREEN);
|
||||
println!(" --debug Build with debug profile (default)");
|
||||
println!(" --release Build with release profile");
|
||||
println!(" --target <triple> Cross-compile for the given target");
|
||||
println!(" --force Force a full rebuild");
|
||||
println!(" --clean Clean before building");
|
||||
println!(" --verbose Print detailed build output");
|
||||
println!(" --workspace <name> Build a specific workspace member");
|
||||
return 0;
|
||||
}
|
||||
|
||||
install_signal_handler();
|
||||
BUILD_INTERRUPTED.store(false, Ordering::SeqCst);
|
||||
let start_dir = match std::env::current_dir() {
|
||||
|
||||
@@ -21,12 +21,27 @@ use crate::core::workspace::parse_workspace;
|
||||
use crate::utils::build::parse_version_info;
|
||||
use crate::utils::fs::{check_dir, find_project_root, with_dir};
|
||||
use crate::utils::log::{error, warn};
|
||||
use crate::utils::text::{BOLD_GREEN, colored};
|
||||
use crate::utils::text::{BOLD_CYAN, BOLD_GREEN, colored, printc};
|
||||
use glob::glob;
|
||||
use std::fs;
|
||||
use std::path::Path;
|
||||
|
||||
pub fn clean(args: &[String]) -> i32 {
|
||||
if args.first().map_or(false, |a| a == "--help") {
|
||||
printc("USAGE:", BOLD_GREEN);
|
||||
printc(" dcr clean [--debug | --release] [--target <triple>] [--all]", BOLD_CYAN);
|
||||
println!();
|
||||
printc("DESCRIPTION:", BOLD_GREEN);
|
||||
println!(" Removes build artifacts from the target directory.");
|
||||
println!();
|
||||
printc("OPTIONS:", BOLD_GREEN);
|
||||
println!(" --debug Clean debug artifacts (default)");
|
||||
println!(" --release Clean release artifacts");
|
||||
println!(" --target <triple> Clean artifacts for a specific target");
|
||||
println!(" --all Clean all workspace members");
|
||||
return 0;
|
||||
}
|
||||
|
||||
let start_dir = match std::env::current_dir() {
|
||||
Ok(dir) => dir,
|
||||
Err(_) => {
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::utils::log::{error, warn};
|
||||
use crate::utils::text::{BOLD_CYAN, BOLD_GREEN, printc};
|
||||
use reqwest::blocking::Client;
|
||||
use serde::Deserialize;
|
||||
use std::fs;
|
||||
@@ -39,6 +40,15 @@ struct ReleaseAsset {
|
||||
}
|
||||
|
||||
pub fn flag_update(args: &[String]) -> i32 {
|
||||
if args.first().map_or(false, |a| a == "--help") {
|
||||
printc("USAGE:", BOLD_GREEN);
|
||||
printc(" dcr --update", BOLD_CYAN);
|
||||
println!();
|
||||
printc("DESCRIPTION:", BOLD_GREEN);
|
||||
println!(" Updates DCR to the latest version from GitHub Releases.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if !args.is_empty() {
|
||||
warn("Command does not support additional arguments");
|
||||
return 1;
|
||||
|
||||
@@ -16,11 +16,21 @@
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::utils::log::error;
|
||||
use crate::utils::text::{BOLD_GREEN, colored};
|
||||
use crate::utils::text::{BOLD_CYAN, BOLD_GREEN, colored, printc};
|
||||
use glob::glob;
|
||||
use std::process::Command;
|
||||
|
||||
pub fn fmt(_args: &[String]) -> i32 {
|
||||
pub fn fmt(args: &[String]) -> i32 {
|
||||
if args.first().map_or(false, |a| a == "--help") {
|
||||
printc("USAGE:", BOLD_GREEN);
|
||||
printc(" dcr fmt", BOLD_CYAN);
|
||||
println!();
|
||||
printc("DESCRIPTION:", BOLD_GREEN);
|
||||
println!(" Formats all C/C++ source files using clang-format.");
|
||||
println!(" Scans src/ and tests/ directories recursively.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
let patterns = [
|
||||
"src/**/*.c",
|
||||
"src/**/*.cpp",
|
||||
|
||||
@@ -27,6 +27,7 @@ use crate::utils::build::{
|
||||
};
|
||||
use crate::utils::fs::find_project_root;
|
||||
use crate::utils::log::error;
|
||||
use crate::utils::text::{BOLD_CYAN, BOLD_GREEN, printc};
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
/// Like `deps::resolve_deps` but does NOT require lib directories to exist.
|
||||
@@ -186,13 +187,30 @@ pub struct ProjectInfo {
|
||||
|
||||
pub fn r#gen(args: &[String]) -> i32 {
|
||||
let subcommand = match args.first() {
|
||||
Some(s) if s == "--help" => {
|
||||
printc("USAGE:", BOLD_GREEN);
|
||||
printc(" dcr gen <subcommand>", BOLD_CYAN);
|
||||
println!();
|
||||
printc("DESCRIPTION:", BOLD_GREEN);
|
||||
println!(" Generates IDE and tooling integration files.");
|
||||
println!();
|
||||
printc("SUBCOMMANDS:", BOLD_GREEN);
|
||||
println!(" project-info Print project metadata as JSON");
|
||||
println!(" compile-commands Generate compile_commands.json");
|
||||
println!(" vscode Generate .vscode/ integration files");
|
||||
println!(" clion Generate .idea/ integration files");
|
||||
return 0;
|
||||
}
|
||||
Some(s) => s.as_str(),
|
||||
None => {
|
||||
eprintln!("Usage: dcr gen <subcommand>");
|
||||
eprintln!(" project-info Print project metadata as JSON");
|
||||
eprintln!(" compile-commands Generate compile_commands.json");
|
||||
eprintln!(" vscode Generate .vscode/ integration files");
|
||||
eprintln!(" clion Generate .idea/ integration files");
|
||||
printc("USAGE:", BOLD_GREEN);
|
||||
printc(" dcr gen <subcommand>", BOLD_CYAN);
|
||||
println!();
|
||||
printc("SUBCOMMANDS:", BOLD_GREEN);
|
||||
println!(" project-info Print project metadata as JSON");
|
||||
println!(" compile-commands Generate compile_commands.json");
|
||||
println!(" vscode Generate .vscode/ integration files");
|
||||
println!(" clion Generate .idea/ integration files");
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -25,6 +25,16 @@ use std::io::Write;
|
||||
use toml::Value;
|
||||
|
||||
pub fn init(args: &[String]) -> i32 {
|
||||
if args.first().map_or(false, |a| a == "--help") {
|
||||
printc("USAGE:", BOLD_GREEN);
|
||||
printc(" dcr init", BOLD_CYAN);
|
||||
println!();
|
||||
printc("DESCRIPTION:", BOLD_GREEN);
|
||||
println!(" Initializes the current directory as a DCR project.");
|
||||
println!(" The directory must be empty.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if !args.is_empty() {
|
||||
warn("Command does not support additional arguments");
|
||||
return 1;
|
||||
|
||||
@@ -25,6 +25,16 @@ use std::io::Write;
|
||||
use toml::Value;
|
||||
|
||||
pub fn new(args: &[String]) -> i32 {
|
||||
if args.first().map_or(false, |a| a == "--help") {
|
||||
printc("USAGE:", BOLD_GREEN);
|
||||
printc(" dcr new <name>", BOLD_CYAN);
|
||||
println!();
|
||||
printc("DESCRIPTION:", BOLD_GREEN);
|
||||
println!(" Creates a new C/C++ project with the given name.");
|
||||
println!(" The name may only contain ASCII letters, digits, '_' and '-'.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
let items = check_dir(None).unwrap_or_default();
|
||||
|
||||
if args.is_empty() {
|
||||
|
||||
@@ -23,7 +23,7 @@ use crate::utils::build::{normalize_target_os, parse_version_info};
|
||||
use crate::utils::fs::find_project_root;
|
||||
use crate::utils::fs::with_dir;
|
||||
use crate::utils::log::error;
|
||||
use crate::utils::text::{BOLD_GREEN, colored};
|
||||
use crate::utils::text::{BOLD_CYAN, BOLD_GREEN, colored, printc};
|
||||
use std::path::Path;
|
||||
use std::process::Command;
|
||||
|
||||
@@ -56,6 +56,23 @@ fn get_run_cmd(
|
||||
}
|
||||
|
||||
pub fn run(args: &[String]) -> i32 {
|
||||
if args.first().map_or(false, |a| a == "--help") {
|
||||
printc("USAGE:", BOLD_GREEN);
|
||||
printc(" dcr run [--debug | --release] [--target <triple>] [--force] [--clean] [--verbose]", BOLD_CYAN);
|
||||
println!();
|
||||
printc("DESCRIPTION:", BOLD_GREEN);
|
||||
println!(" Builds and runs the project. Only available for kind = \"bin\".");
|
||||
println!();
|
||||
printc("OPTIONS:", BOLD_GREEN);
|
||||
println!(" --debug Run with debug profile (default)");
|
||||
println!(" --release Run with release profile");
|
||||
println!(" --target <triple> Cross-compile for the given target");
|
||||
println!(" --force Force a full rebuild");
|
||||
println!(" --clean Clean before building");
|
||||
println!(" --verbose Print detailed build output");
|
||||
return 0;
|
||||
}
|
||||
|
||||
let start_dir = match std::env::current_dir() {
|
||||
Ok(dir) => dir,
|
||||
Err(_) => {
|
||||
|
||||
@@ -15,7 +15,19 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
pub fn setup(_args: &[String]) -> i32 {
|
||||
use crate::utils::text::{BOLD_CYAN, BOLD_GREEN, printc};
|
||||
|
||||
pub fn setup(args: &[String]) -> i32 {
|
||||
if args.first().map_or(false, |a| a == "--help") {
|
||||
printc("USAGE:", BOLD_GREEN);
|
||||
printc(" dcr setup", BOLD_CYAN);
|
||||
println!();
|
||||
printc("DESCRIPTION:", BOLD_GREEN);
|
||||
println!(" Sets up DCR registries. Downloads and indexes");
|
||||
println!(" package registries for dependency resolution.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
println!("Setting up DCR registries...");
|
||||
match crate::core::registry::RegistryManager::load() {
|
||||
Ok(manager) => {
|
||||
|
||||
@@ -24,7 +24,7 @@ use crate::utils::build::{
|
||||
};
|
||||
use crate::utils::fs::{find_project_root, with_dir};
|
||||
use crate::utils::log::error;
|
||||
use crate::utils::text::{BOLD_GREEN, BOLD_RED, RESET, colored};
|
||||
use crate::utils::text::{BOLD_CYAN, BOLD_GREEN, BOLD_RED, RESET, colored, printc};
|
||||
use std::fs;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::Command;
|
||||
@@ -36,16 +36,16 @@ pub fn test(args: &[String]) -> i32 {
|
||||
let mut profile = "debug";
|
||||
for arg in args {
|
||||
if arg == "--help" {
|
||||
println!("USAGE:");
|
||||
println!(" dcr test [--init] [--debug | --release]");
|
||||
printc("USAGE:", BOLD_GREEN);
|
||||
printc(" dcr test [--init] [--debug | --release]", BOLD_CYAN);
|
||||
println!();
|
||||
println!("ALIASES:");
|
||||
printc("ALIASES:", BOLD_GREEN);
|
||||
println!(" dcr tests");
|
||||
println!();
|
||||
println!("DESCRIPTION:");
|
||||
printc("DESCRIPTION:", BOLD_GREEN);
|
||||
println!(" Runs project tests and prints a unified testsuite report.");
|
||||
println!();
|
||||
println!("OPTIONS:");
|
||||
printc("OPTIONS:", BOLD_GREEN);
|
||||
println!(" --init Create tests/dcr_test.h in current project");
|
||||
println!(" --debug Build and run tests with debug profile (default)");
|
||||
println!(" --release Build and run tests with release profile");
|
||||
|
||||
@@ -17,12 +17,21 @@
|
||||
|
||||
use crate::core::config::Config;
|
||||
use crate::utils::log::error;
|
||||
use crate::utils::text::{BOLD_CYAN, printc};
|
||||
use crate::utils::text::{BOLD_CYAN, BOLD_GREEN, printc};
|
||||
use std::collections::HashSet;
|
||||
use std::path::{Path, PathBuf};
|
||||
use toml::Value;
|
||||
|
||||
pub fn tree(_args: &[String]) -> i32 {
|
||||
pub fn tree(args: &[String]) -> i32 {
|
||||
if args.first().map_or(false, |a| a == "--help") {
|
||||
printc("USAGE:", BOLD_GREEN);
|
||||
printc(" dcr tree", BOLD_CYAN);
|
||||
println!();
|
||||
printc("DESCRIPTION:", BOLD_GREEN);
|
||||
println!(" Displays the dependency tree of the current project.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
let current_dir = std::env::current_dir().unwrap_or_else(|_| PathBuf::from("."));
|
||||
let config = match Config::open("dcr.toml") {
|
||||
Ok(c) => c,
|
||||
|
||||
Reference in New Issue
Block a user