feat: Basic cli sketch
This commit is contained in:
parent
d7c7cffa1b
commit
715b578bb9
|
@ -7,10 +7,8 @@ description = "Djot based static site generator"
|
|||
readme = "README.md"
|
||||
license = "MIT"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
clap = { version = "4.1.8", features = ["derive"] }
|
||||
clap = { version = "4.1.8", features = ["derive", "env"] }
|
||||
color-eyre = "0.6.2"
|
||||
jotdown = "0.1.0"
|
||||
serde = { version = "1.0.156", features = ["derive"] }
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
use clap::Args;
|
||||
use color_eyre::eyre::Result;
|
||||
use tracing::instrument;
|
||||
|
||||
use super::GlobalArgs;
|
||||
|
||||
/// Arguments for the init subcommand
|
||||
#[derive(Args, Debug)]
|
||||
pub struct InitArgs {
|
||||
/// Domain name to use
|
||||
#[arg(long, short)]
|
||||
pub doman_name: Option<String>,
|
||||
}
|
||||
|
||||
impl InitArgs {
|
||||
/// Run the init command
|
||||
#[instrument]
|
||||
pub fn run(self, _globals: GlobalArgs) -> Result<()> {
|
||||
println!("Hello world!");
|
||||
Ok(())
|
||||
}
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
use clap::{Args, Parser, Subcommand};
|
||||
use color_eyre::eyre::Result;
|
||||
use std::path::PathBuf;
|
||||
|
||||
mod init;
|
||||
|
||||
pub use init::InitArgs;
|
||||
|
||||
/// Djot based static site generator
|
||||
#[derive(Parser, Debug)]
|
||||
#[command(author, version, about, long_about=None)]
|
||||
pub struct Cli {
|
||||
#[command(flatten)]
|
||||
#[command(next_help_heading = "Global Options")]
|
||||
pub global_args: GlobalArgs,
|
||||
/// Command to run
|
||||
#[command(subcommand)]
|
||||
pub command: Command,
|
||||
}
|
||||
|
||||
/// Global arguments to the command
|
||||
#[derive(Args, Debug)]
|
||||
pub struct GlobalArgs {
|
||||
/// Path of the site source repository
|
||||
#[arg(long, value_name = "SITE_PATH", env = "STRANGER_SITE_PATH")]
|
||||
#[clap(global = true)]
|
||||
pub site_path: Option<PathBuf>,
|
||||
}
|
||||
|
||||
/// Command to run
|
||||
#[derive(Subcommand, Debug)]
|
||||
pub enum Command {
|
||||
/// Initialize a site
|
||||
Init(InitArgs),
|
||||
}
|
||||
|
||||
impl Command {
|
||||
/// Run the init command
|
||||
pub fn run(self, globals: GlobalArgs) -> Result<()> {
|
||||
match self {
|
||||
Command::Init(args) => args.run(globals),
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,3 +1,15 @@
|
|||
fn main() {
|
||||
println!("Hello world!");
|
||||
mod cli;
|
||||
|
||||
use cli::Cli;
|
||||
|
||||
use clap::Parser;
|
||||
use color_eyre::eyre::Result;
|
||||
|
||||
fn main() -> Result<()> {
|
||||
// Setup color eyre and logging
|
||||
color_eyre::install()?;
|
||||
tracing_subscriber::fmt::init();
|
||||
|
||||
let args = Cli::parse();
|
||||
args.command.run(args.global_args)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue