Add very basic CLI.
This commit is contained in:
67
src/main.rs
67
src/main.rs
@@ -1,3 +1,66 @@
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
use clap::Args;
|
||||
use clap::Parser;
|
||||
use clap::Subcommand;
|
||||
use std::path::PathBuf;
|
||||
use std::process::ExitCode;
|
||||
|
||||
fn main() -> Result<ExitCode, Box<dyn std::error::Error>> {
|
||||
let rt = tokio::runtime::Runtime::new()?;
|
||||
rt.block_on(async {
|
||||
let main_body_result = main_body().await;
|
||||
main_body_result
|
||||
})
|
||||
}
|
||||
|
||||
async fn main_body() -> Result<ExitCode, Box<dyn std::error::Error>> {
|
||||
let args = Cli::parse();
|
||||
match args.command {
|
||||
Commands::Init(_args) => {}
|
||||
Commands::Build(_args) => {}
|
||||
Commands::AddPost(_args) => {}
|
||||
};
|
||||
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,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user