Skip to content

Commit

Permalink
feat: Allow opening specific file via a CLI argument
Browse files Browse the repository at this point in the history
  • Loading branch information
wentasah committed Oct 9, 2024
1 parent 711150b commit f8d33af
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ Arguments:
[ROOT] Set the root path of the static assets [default: .]

Options:
-H, --host <HOST> Set the listener host [default: 0.0.0.0]
-p, --port <PORT> Set the listener port [default: 0]
-o, --open Open the page in browser automatically
--hard Hard reload the page on update instead of hot reload
-h, --help Print help (see more with '--help')
-V, --version Print version
-H, --host <HOST> Set the listener host [default: 0.0.0.0]
-p, --port <PORT> Set the listener port [default: 0]
-o, --open [<PAGE>] Open the page in browser automatically
--hard Hard reload the page on update instead of hot reload
-h, --help Print help (see more with '--help')
-V, --version Print version
```

```console
Expand Down
11 changes: 6 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ struct Args {
#[clap(short, long, default_value = "0")]
port: u16,
/// Open the page in browser automatically
#[clap(short, long)]
open: bool,
#[clap(short, long, value_name = "PAGE")]
open: Option<Option<String>>,
/// Hard reload the page on update instead of hot reload
///
/// Try using this if the reload is not working as expected
Expand All @@ -41,9 +41,10 @@ async fn main() {
let addr = format!("{}:{}", host, port);
let mut listener = listen(addr, root).await.unwrap();

if open {
let link = listener.link().unwrap();
open::that(link).unwrap();
if let Some(page) = open {
let origin = listener.link().unwrap();
let path = page.unwrap_or_default();
open::that(format!("{origin}/{path}")).unwrap();
}

if hard {
Expand Down

0 comments on commit f8d33af

Please sign in to comment.