-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from jubako/better_serve
Move serve subcommand in its own submodule.
- Loading branch information
Showing
3 changed files
with
37 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use anyhow::{Context, Result}; | ||
use clap::Parser; | ||
use log::info; | ||
use std::path::PathBuf; | ||
|
||
/// Serve the waj archive on the web. | ||
#[derive(Parser)] | ||
pub struct Options { | ||
/// Archive to serve | ||
#[arg(value_parser)] | ||
infile: PathBuf, | ||
|
||
/// On which address serve the archive. | ||
#[arg(value_parser, default_value = "localhost:1234")] | ||
address: String, | ||
|
||
#[arg(from_global)] | ||
verbose: u8, | ||
} | ||
|
||
pub fn serve(options: Options) -> Result<()> { | ||
info!( | ||
"Serve archive {:?} at {:?}", | ||
options.infile, options.address, | ||
); | ||
let server = waj::Server::new(&options.infile) | ||
.with_context(|| format!("Opening {:?}", options.infile))?; | ||
Ok(server.serve(&options.address)?) | ||
} |