Commit Diff


commit - cd7cf0434f173b3ac135f2678ab38d1bc82f19c4
commit + efda331aa8bf3fb18f7cea38418e5952f02852f2
blob - 1f0bdc5d8d60527216ca468236c6cfb3619cf0e1
blob + ce4957150b697c632c627350f6f40583bd365976
--- Justfile
+++ Justfile
@@ -4,7 +4,16 @@ default:
 generate-all:
     just web
     just lib
+    just cli
 
+
+cli $CARGO_NAME="your name" $CARGO_EMAIL="author@example.com":
+    rm -rv cli-generated
+    cargo generate --path ./cli \
+        --name cli-generated \
+        --define project-description="An example generated using the cli template" \
+        --define use-gitserver=false
+
 web $CARGO_NAME="your name" $CARGO_EMAIL="author@example.com":
     rm -rv web-generated
     cargo generate --path ./web \
blob - d61343292b8e3dcb2d1dd9dd76f375b3f29bb665
blob + af89a1e19b68321c168012ae15d296f849cd6240
--- cargo-generate.toml
+++ cargo-generate.toml
@@ -5,4 +5,5 @@ cargo_generate_version = ">=0.23.0"
 sub_templates = [
   "web",
   "lib",
+  "cli",
 ]
blob - /dev/null
blob + e1ed2418d4fd1fd423104d2a27695588b0183691 (mode 644)
--- /dev/null
+++ cli/README.md
@@ -0,0 +1,2 @@
+# cli template
+
blob - /dev/null
blob + d6c3cc68c2000702228b5bffcca841b63963bf2d (mode 644)
--- /dev/null
+++ cli/template/.editorconfig
@@ -0,0 +1,11 @@
+# https://EditorConfig.org
+root = true
+
+[*]
+charset = utf-8
+trim_trailing_whitespace = true
+end_of_line = lf
+insert_final_newline = true
+indent_style = space
+indent_size = 4
+
blob - /dev/null
blob + 9fbc864de99bc6d43ce1b8d3e72609f3d862ec28 (mode 644)
--- /dev/null
+++ cli/template/.gitignore
@@ -0,0 +1,2 @@
+target/
+tmp/
blob - /dev/null
blob + 3aff51c5b56dec78c9a639db715ea6fc5ca591ef (mode 644)
--- /dev/null
+++ cli/template/.rustfmt.toml
@@ -0,0 +1,19 @@
+style_edition = "2024"
+max_width = 79
+# Make Rust more readable given most people have wide screens nowadays.
+# This is also the setting used by [rustc](https://github.com/rust-lang/rust/blob/master/rustfmt.toml)
+use_small_heuristics = "Max"
+
+# Use field initialize shorthand if possible
+use_field_init_shorthand = true
+
+reorder_modules = true
+
+# All unstable features that we wish for
+# unstable_features = true
+# Provide a cleaner impl order
+# reorder_impl_items = true
+# Provide a cleaner import sort order
+# group_imports = "StdExternalCrate"
+# Group "use" statements by crate
+# imports_granularity = "Crate"
blob - /dev/null
blob + 41f977e156c9598f3b3907dbc74c8034d2b8436b (mode 644)
--- /dev/null
+++ cli/template/Cargo.toml
@@ -0,0 +1,61 @@
+[package]
+name = "{{project-name}}"
+version = "0.1.0"
+
+authors = ["{{authors}}"]
+description = "{{project-description}}"
+edition = "2024"
+license = "ISC"
+
+#
+# lints
+#
+
+[lints.rust]
+absolute_paths_not_starting_with_crate = "warn"
+non_ascii_idents = "warn"
+tail_expr_drop_order = "warn"
+unexpected_cfgs = { level = "warn", check-cfg = ['cfg(coverage)', 'cfg(coverage_nightly)'] }
+unit-bindings = "warn"
+unsafe_op_in_unsafe_fn = "warn"
+unused_unsafe = "warn"
+
+[lints.clippy]
+all = { level = "warn", priority = -1 }
+
+#
+# dep
+#
+
+[dependencies]
+anyhow = "=1.0.100"
+clap = { version = "=4.5.53", features = ["derive"] }
+env_logger = "=0.11.8"
+log = "=0.4.28"
+
+#
+# profiles
+#
+
+[profile.dev]
+debug = false
+
+[profile.test]
+debug = false
+
+[profile.release-with-debug]
+inherits = "release"
+strip = false
+debug = true
+
+[profile.coverage]
+inherits = "release"
+opt-level = 2
+codegen-units = 256
+lto = "thin"
+debug-assertions = true
+overflow-checks = true
+
+[profile.dev-no-debug-assertions]
+inherits = "dev"
+debug-assertions = false
blob - /dev/null
blob + d75154570f871d95f17777a70cb7cd7f874032a4 (mode 644)
--- /dev/null
+++ cli/template/Justfile
@@ -0,0 +1,38 @@
+#!/usr/bin/env -S just --justfile
+
+_default:
+  @just --list -u
+
+# ==================== ALIASES ====================
+alias r := ci
+
+# ==================== SETUP & INITIALIZATION ====================
+
+# Install git pre-commit hook to format files
+install-hook:
+  echo -e "#!/bin/sh\njust fmt" > .git/hooks/pre-commit
+  chmod +x .git/hooks/pre-commit
+
+# ==================== CORE DEVELOPMENT ====================
+
+watch +args='test --all':
+  cargo watch --clear --exec '{{args}}'
+
+ci:
+  cargo test --all
+  cargo clippy --all
+  cargo fmt --all -- --check
+
+# publish current master branch
+publish:
+  #!/usr/bin/env bash
+  set -euxo pipefail
+  rm -rf tmp/release
+  git clone git@github.com
+  VERSION=`sed -En 's/version[[:space:]]*=[[:space:]]*"([^"]+)"/\1/p' Cargo.toml | head -1`
+  cd tmp/release
+  git tag -a $VERSION -m "Release $VERSION"
+  git push origin $VERSION
+  cargo publish
+  cd ../..
+  rm -rf tmp/release
blob - /dev/null
blob + 1d0d9244f35adb07ec6842c510b84af71c16b073 (mode 644)
--- /dev/null
+++ cli/template/LICENSE
@@ -0,0 +1,13 @@
+Copyright (c) 2025 murilo ijanc' <murilo@ijanc.org>
+
+Permission to use, copy, modify, and distribute this software for any
+purpose with or without fee is hereby granted, provided that the above
+copyright notice and this permission notice appear in all copies.
+
+THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
blob - /dev/null
blob + 3dcf61b571e7e37cb3e85018179e3d5e8667907e (mode 644)
--- /dev/null
+++ cli/template/README.md
@@ -0,0 +1,11 @@
+# {{project-name}}
+
+## Run
+
+```
+RUST_LOG=debug cargo run
+```
+
+## License
+
+This project is licensed under the ISC license ([LICENSE](LICENSE) or http://opensource.org/licenses/ISC)
blob - /dev/null
blob + 52cbd9f00560c3e51825d34c71c8f12715b94c6f (mode 644)
--- /dev/null
+++ cli/template/build.rs
@@ -0,0 +1,21 @@
+use std::process::Command;
+
+fn main() {
+    let git_hash = Command::new("git")
+        .args(["rev-parse", "HEAD"])
+        .output()
+        .map(|out| String::from_utf8_lossy(&out.stdout).trim().to_string())
+        .unwrap_or_else(|_| "unknown".into());
+
+    let git_date = Command::new("git")
+        .args(["show", "-s", "--format=%cI", "HEAD"])
+        .output()
+        .map(|out| String::from_utf8_lossy(&out.stdout).trim().to_string())
+        .unwrap_or_else(|_| "unknown".into());
+
+    println!("cargo:rustc-env=GIT_HASH={}", git_hash);
+    println!("cargo:rustc-env=BUILD_DATE={}", git_date);
+
+    println!("cargo:rerun-if-changed=.git/HEAD");
+    println!("cargo:rerun-if-changed=.git/refs/heads");
+}
blob - /dev/null
blob + ec598e7aeffec900c5789433edba560252bac5d4 (mode 644)
--- /dev/null
+++ cli/template/cargo-generate.toml
@@ -0,0 +1,5 @@
+[template]
+cargo_generate_version = ">=0.23.0"
+
+[placeholders]
+project-description = { type = "string", prompt = "Short description of the project", default = "An example generated using the simple template" }
blob - /dev/null
blob + 74406feca38d201018448fb14b64eaa5df44b5b8 (mode 644)
--- /dev/null
+++ cli/template/dprint.json
@@ -0,0 +1,24 @@
+{
+  "markdown": {
+  },
+  "toml": {
+  },
+  "excludes": [
+  ],
+  "exec": {
+    "cwd": "${configDir}",
+    "commands": [{
+      "command": "rustfmt",
+      "exts": ["rs"],
+      "cacheKeyFiles": [
+        ".rustfmt.toml",
+        "rust-toolchain.toml"
+      ]
+    }]
+  },
+  "plugins": [
+    "https://plugins.dprint.dev/markdown-0.20.0.wasm",
+    "https://plugins.dprint.dev/toml-0.7.0.wasm",
+    "https://plugins.dprint.dev/exec-0.6.0.json@a054130d458f124f9b5c91484833828950723a5af3f8ff2bd1523bd47b83b364"
+  ]
+}
blob - /dev/null
blob + 02cb8fcb5372748d4273b6a49eceb78fbdb15ce6 (mode 644)
--- /dev/null
+++ cli/template/rust-toolchain.toml
@@ -0,0 +1,3 @@
+[toolchain]
+channel = "stable"
+profile = "default"
blob - /dev/null
blob + 575cc3db95fe075fb60da3953d2325fb80caad17 (mode 644)
--- /dev/null
+++ cli/template/src/main.rs
@@ -0,0 +1,72 @@
+//
+// Copyright (c) 2025 murilo ijanc' <murilo@ijanc.org>
+//
+// Permission to use, copy, modify, and distribute this software for any
+// purpose with or without fee is hereby granted, provided that the above
+// copyright notice and this permission notice appear in all copies.
+//
+// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+//
+
+use anyhow::Result;
+use clap::{ArgAction, Parser};
+use log::{LevelFilter, info, debug};
+
+const LONG_VERSION: &str = concat!(
+    env!("CARGO_PKG_NAME"),
+    " ",
+    env!("CARGO_PKG_VERSION"),
+    " (",
+    env!("GIT_HASH", "unknown"),
+    " ",
+    env!("BUILD_DATE", "unknown"),
+    ")",
+);
+
+#[derive(Debug, Parser)]
+#[command(
+    name = "{{project-name}}",
+    about = "{{project-description}}",
+    version = env!("CARGO_PKG_VERSION"),
+    long_version = LONG_VERSION,
+    author,
+    propagate_version = true
+)]
+struct Args {
+    /// Increase verbosity (use -v, -vv, ...).
+    ///
+    /// When no RUST_LOG is set, a single -v switches the log level to DEBUG.
+    #[arg(short, long, global = true, action = ArgAction::Count)]
+    verbose: u8,
+}
+
+fn main() -> Result<()> {
+    let args = Args::parse();
+
+    init_logger(args.verbose);
+
+    info!("hello world cli");
+    debug!("hello world cli");
+
+    Ok(())
+}
+
+fn init_logger(verbose: u8) {
+    use std::io::Write;
+
+    let level =
+        if verbose > 0 { LevelFilter::Debug } else { LevelFilter::Info };
+
+    env_logger::builder()
+        .filter(None, level)
+        .format(|buf, record| {
+            writeln!(buf, "[{}]: {}", record.level(), record.args())
+        })
+        .init();
+}