Add 'run' subcommand

For future extensibility
This commit is contained in:
Xiretza 2024-02-20 21:59:43 +00:00
parent aecf9509f5
commit a52567330a
2 changed files with 15 additions and 2 deletions

View file

@ -85,4 +85,4 @@ updater-server=http://invalid.example
### Running factoriauth
Either use `cargo install --path .` and follow its instructions for how to update `$PATH`, then run
`factoriauth`, or run the program straight from the repository: `cargo run`.
`factoriauth run`, or run the program straight from the repository: `cargo run -- run`.

View file

@ -35,7 +35,7 @@ use std::{env, path::PathBuf, sync::Arc};
use auth::{
AuthenticationBackend, ServerPadlockGenerator, UserAuthenticator, UserServerKeyGenerator,
};
use clap::Parser;
use clap::{Parser, Subcommand};
use color_eyre::{eyre::Context, Result};
use config::Config;
use db::{Database, SqliteDatabase};
@ -92,11 +92,20 @@ async fn load_config(path: &str) -> Result<Config> {
Ok(toml::from_str(&content)?)
}
#[derive(Debug, Clone, Subcommand)]
enum Command {
/// Run factoriauth
Run,
}
#[derive(Debug, Clone, Parser)]
struct Args {
/// Path to the configuration file.
#[arg(short, long, default_value = "config.toml")]
config: String,
#[command(subcommand)]
command: Command,
}
#[tokio::main]
@ -104,6 +113,10 @@ struct Args {
async fn main() -> Result<()> {
let args = Args::parse();
match args.command {
Command::Run => {}
}
init().context("Failed to initialize tracing")?;
let config = load_config(&args.config).await.with_context(|| {