Move the CLI to a module.
This commit is contained in:
parent
1b189cf15c
commit
a1f4600483
1
src/cli/mod.rs
Normal file
1
src/cli/mod.rs
Normal file
@ -0,0 +1 @@
|
||||
pub(crate) mod parameters;
|
47
src/cli/parameters.rs
Normal file
47
src/cli/parameters.rs
Normal file
@ -0,0 +1,47 @@
|
||||
use clap::Args;
|
||||
use clap::Parser;
|
||||
use clap::Subcommand;
|
||||
use std::path::PathBuf;
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
#[command(name = "Writer")]
|
||||
#[command(version = env!("CARGO_PKG_VERSION"))]
|
||||
#[command(about = "Generate a static site.", long_about = None)]
|
||||
#[command(propagate_version = true)]
|
||||
pub(crate) struct Cli {
|
||||
#[command(subcommand)]
|
||||
pub(crate) command: Commands,
|
||||
}
|
||||
|
||||
#[derive(Subcommand, Debug)]
|
||||
pub(crate) enum Commands {
|
||||
/// Initialize an empty website folder.
|
||||
Init(InitArgs),
|
||||
|
||||
/// Build the static site.
|
||||
Build(BuildArgs),
|
||||
|
||||
/// Add a blog post to the site.
|
||||
AddPost(BuildArgs),
|
||||
}
|
||||
|
||||
#[derive(Args, Debug)]
|
||||
pub(crate) struct InitArgs {
|
||||
/// Path where you want the initial writer structure to be located.
|
||||
#[arg(short, long)]
|
||||
pub(crate) path: PathBuf,
|
||||
}
|
||||
|
||||
#[derive(Args, Debug)]
|
||||
pub(crate) struct BuildArgs {
|
||||
/// Path to the writer config file.
|
||||
#[arg(short, long)]
|
||||
pub(crate) config: PathBuf,
|
||||
}
|
||||
|
||||
#[derive(Args, Debug)]
|
||||
pub(crate) struct AddPostArgs {
|
||||
/// Path to the writer config file.
|
||||
#[arg(short, long)]
|
||||
pub(crate) config: PathBuf,
|
||||
}
|
53
src/main.rs
53
src/main.rs
@ -1,9 +1,11 @@
|
||||
use clap::Args;
|
||||
use clap::Parser;
|
||||
use clap::Subcommand;
|
||||
use std::path::PathBuf;
|
||||
use std::process::ExitCode;
|
||||
|
||||
use clap::Parser;
|
||||
|
||||
use self::cli::parameters::Cli;
|
||||
use self::cli::parameters::Commands;
|
||||
mod cli;
|
||||
|
||||
fn main() -> Result<ExitCode, Box<dyn std::error::Error>> {
|
||||
let rt = tokio::runtime::Runtime::new()?;
|
||||
rt.block_on(async {
|
||||
@ -21,46 +23,3 @@ async fn main_body() -> Result<ExitCode, Box<dyn std::error::Error>> {
|
||||
};
|
||||
Ok(ExitCode::SUCCESS)
|
||||
}
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
#[command(name = "Writer")]
|
||||
#[command(version = env!("CARGO_PKG_VERSION"))]
|
||||
#[command(about = "Generate a static site.", long_about = None)]
|
||||
#[command(propagate_version = true)]
|
||||
struct Cli {
|
||||
#[command(subcommand)]
|
||||
command: Commands,
|
||||
}
|
||||
|
||||
#[derive(Subcommand, Debug)]
|
||||
enum Commands {
|
||||
/// Initialize an empty website folder.
|
||||
Init(InitArgs),
|
||||
|
||||
/// Build the static site.
|
||||
Build(BuildArgs),
|
||||
|
||||
/// Add a blog post to the site.
|
||||
AddPost(BuildArgs),
|
||||
}
|
||||
|
||||
#[derive(Args, Debug)]
|
||||
struct InitArgs {
|
||||
/// Path where you want the initial writer structure to be located.
|
||||
#[arg(short, long)]
|
||||
path: PathBuf,
|
||||
}
|
||||
|
||||
#[derive(Args, Debug)]
|
||||
struct BuildArgs {
|
||||
/// Path to the writer config file.
|
||||
#[arg(short, long)]
|
||||
config: PathBuf,
|
||||
}
|
||||
|
||||
#[derive(Args, Debug)]
|
||||
struct AddPostArgs {
|
||||
/// Path to the writer config file.
|
||||
#[arg(short, long)]
|
||||
config: PathBuf,
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user