Skip to content

Commit

Permalink
Add --web flag to brief subcommand
Browse files Browse the repository at this point in the history
Opens the original brief in your web browser.
  • Loading branch information
nuxeh committed Dec 11, 2021
1 parent e1390e0 commit 7f066f3
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
- **Added** `--web` flag for `brief` subcommand

# v0.1.17

- **Added** feature to make html parsing optional
Expand Down
18 changes: 18 additions & 0 deletions aocf_cli/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions aocf_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ termimad = "0.9.1"
crossterm = "0.17.7"
regex = "1.4.2"
structopt = "0.3.21"
webbrowser = "0.5.5"

[package.metadata.deb]
extended-description = """\
Expand Down
4 changes: 4 additions & 0 deletions aocf_cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ Only available for the `brief` subcommand, pretty formats the challenge brief
in a similar format to viewing on the Advent of Code website, in a scrollable,
pager fashion.

* `--web`

Only available for the `brief` subcommand, opens the brief in a web browser.

### Retrieval flags

* `--force`
Expand Down
20 changes: 15 additions & 5 deletions aocf_cli/src/bin/aocf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use failure::{Error, bail, format_err};
use regex::Regex;
use structopt::StructOpt;
use chrono::{Utc, Datelike};

use webbrowser;

fn main() {
let opt = Aocf::from_args();
Expand Down Expand Up @@ -93,7 +93,7 @@ fn run(args: &Aocf) -> Result<(), Error> {
let _ = aoc.get_input(*force)?;
aoc.write()?;
},
Aocf::Brief { pretty, view, force, now, day } => {
Aocf::Brief { pretty, view, force, now, day, web } => {
aoc = if *now {
let now = Utc::now();
Aoc::new()
Expand All @@ -111,9 +111,19 @@ fn run(args: &Aocf) -> Result<(), Error> {
aoc
};

let brief = aoc.get_brief(*force)?;
aoc.write()?;
display(*pretty, *view, &conf, &brief)?
if *web {
if let (Some(d), Some(y)) = (aoc.day, aoc.year) {
let url = format!("https://adventofcode.com/{}/day/{}", y, d);
match webbrowser::open(&url) {
Ok(_) => eprintln!("opened brief for day {}, year {} in web browser", d, y),
Err(e) => eprintln!("error opening brief in web browser: {}", e),
};
}
} else {
let brief = aoc.get_brief(*force)?;
aoc.write()?;
display(*pretty, *view, &conf, &brief)?
}
},
Aocf::Input { view, force } => {
let input = aoc.get_input(*force)?;
Expand Down
4 changes: 4 additions & 0 deletions aocf_cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ pub enum Aocf {
#[structopt(short, long, conflicts_with = "pretty")]
view: bool,

/// View in web browser
#[structopt(short, long, conflicts_with_all = &["pretty", "view"])]
web: bool,

/// View current day and year
#[structopt(short, long, conflicts_with = "day")]
now: bool,
Expand Down

0 comments on commit 7f066f3

Please sign in to comment.