initial commit - laid out stuff
This commit is contained in:
commit
0d0cb945a1
6 changed files with 463 additions and 0 deletions
38
src/build.rs
Normal file
38
src/build.rs
Normal file
|
@ -0,0 +1,38 @@
|
|||
use crate::cli::Cli;
|
||||
use clap::CommandFactory;
|
||||
use clap_complete::aot::{Bash, Elvish, Fish, PowerShell, Zsh, generate_to};
|
||||
use std::env;
|
||||
use std::io::Error;
|
||||
use std::process::exit;
|
||||
|
||||
pub(crate) fn completion_builder() -> Result<(), Error> {
|
||||
let outdir = match env::var_os("OUT_DIR") {
|
||||
None => return Ok(()),
|
||||
Some(outdir) => outdir,
|
||||
};
|
||||
let mut cmd = Cli::command();
|
||||
|
||||
// this is bad but whatever
|
||||
println!(
|
||||
"bash completion file generated: {:?}",
|
||||
generate_to(Bash, &mut cmd, "shoe", &outdir,)?
|
||||
);
|
||||
println!(
|
||||
"elvish completion file generated: {:?}",
|
||||
generate_to(Elvish, &mut cmd, "shoe", &outdir,)?
|
||||
);
|
||||
println!(
|
||||
"fish completion file generated: {:?}",
|
||||
generate_to(Fish, &mut cmd, "shoe", &outdir,)?
|
||||
);
|
||||
println!(
|
||||
"powershell completion file generated: {:?}",
|
||||
generate_to(PowerShell, &mut cmd, "shoe", &outdir,)?
|
||||
);
|
||||
println!(
|
||||
"zsh completion file generated: {:?}",
|
||||
generate_to(Zsh, &mut cmd, "shoe", &outdir,)?
|
||||
);
|
||||
|
||||
exit(0);
|
||||
}
|
10
src/cli.rs
Normal file
10
src/cli.rs
Normal file
|
@ -0,0 +1,10 @@
|
|||
use std::path::PathBuf;
|
||||
|
||||
use clap::Parser;
|
||||
|
||||
#[derive(Parser)]
|
||||
#[command(version, about, long_about = None)]
|
||||
pub(crate) struct Cli {
|
||||
#[arg(short, long, value_name = "FILE", default_value = "shoe.conf")]
|
||||
pub(crate) config: PathBuf,
|
||||
}
|
46
src/main.rs
Normal file
46
src/main.rs
Normal file
|
@ -0,0 +1,46 @@
|
|||
use clap::Parser;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::{collections::HashMap, path::PathBuf};
|
||||
mod build;
|
||||
mod cli;
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, PartialEq)]
|
||||
struct SiteInfo {
|
||||
name: String,
|
||||
subdomain: String,
|
||||
///
|
||||
socket_address_or_port: String,
|
||||
/// What auth file to use
|
||||
auth: u8,
|
||||
conf_file: PathBuf,
|
||||
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, PartialEq)]
|
||||
struct Config {
|
||||
output_dir: String,
|
||||
domain: String,
|
||||
/// Subdomains/services in the format `subdomain: SiteInfo`
|
||||
subdomains: HashMap<String, SiteInfo>,
|
||||
/// Paths to the htpasswd file for each auth number - starts at 0, goes to 255; see [`SiteInfo`]
|
||||
htpasswd_files: Vec<PathBuf>,
|
||||
/// Default IP for if it's not specified in `socket_address_or_port` in [`SiteInfo`]. Defaults to localhost if not specified.
|
||||
#[serde(default = "default_default_ip")]
|
||||
default_ip: String
|
||||
}
|
||||
|
||||
fn main() {
|
||||
build::completion_builder().unwrap();
|
||||
|
||||
let args = cli::Cli::parse();
|
||||
|
||||
let config = args.config;
|
||||
|
||||
println!("Config: {}", config.to_str().unwrap())
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------
|
||||
|
||||
fn default_default_ip() -> String {
|
||||
return "localhost".to_string();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue