Skip to content

Commit

Permalink
Define init command args
Browse files Browse the repository at this point in the history
  • Loading branch information
connorslade committed Nov 26, 2023
1 parent 84625aa commit f05148d
Show file tree
Hide file tree
Showing 8 changed files with 271 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/scaffold.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: bin
name: scaffold
on:
workflow_dispatch:
push:
Expand Down
201 changes: 201 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions scaffold/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ edition = "2021"

[dependencies]
anyhow = "1.0.75"
chrono = "0.4.31"
clap = { version = "4.4.8", features = ["derive"] }
colored = "2.0.4"
globalenv = "0.4.2"
once_cell = "1.18.0"
scraper = "0.18.1"
Expand Down
41 changes: 40 additions & 1 deletion scaffold/src/args.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use clap::Parser;
use url::Url;

use crate::misc::current_year;

#[derive(Parser, Debug)]
pub struct Args {
/// The session token to use for the request.
Expand All @@ -25,5 +27,42 @@ pub enum SubCommand {
},
/// Fetch the puzzle input for a given day and write to a file.
/// Also creates a base solution file for the given day.
Init { day: u8, year: Option<u16> },
Init(InitArgs),
/// Waits for midnight in EST (UTC-5) then returns.
/// Chaining this command with another command, like init, will ensure that the input is fetched as soon as it is available.
Timer,
}

#[derive(Parser, Debug)]
pub struct InitArgs {
/// A formatter that will be used to get the path for the input file.
#[arg(short, long, default_value = "{year}/{day:pad}.txt")]
input_location: String,
/// A formatter that will be used to get the path for the solution file.
#[arg(short, long, default_value = "aoc_{year}/src/day_{day:pad}.rs")]
solution_location: String,
/// Location formatter of the file importing each solution module.
#[arg(long, default_value = "aoc_{year}/src/lib.rs")]
module_location: String,
/// A formatter for a new line that will be added to the module file before the marker.
#[arg(long, default_values_t = ["mod day_{day:pad};".to_owned(), "&day_{day:pad}::Day{day:pad},".to_owned()])]
module_templates: Vec<String>,
/// A marker is a string that will be found in the module file and is used to determine where to insert the new line.
/// If not provided, the default markers will be used.
#[arg(long, default_values_t = ["// [import_marker]".to_owned(), "// [list_marker]".to_owned()])]
module_markers: Vec<String>,
/// Path to a template file that will be used to create the solution file.
/// If not provided, a default template will be used.
#[arg(short = 't', long)]
solution_template: Option<String>,
/// Don't create a solution file.
/// Useful if you want to use this command with a different language or organization.
#[arg(short, long)]
no_scaffold: bool,

/// The day to fetch the input for.
day: u8,
/// The year to fetch the input for.
#[arg(default_value_t = current_year())]
year: u16,
}
5 changes: 3 additions & 2 deletions scaffold/src/commands/verify.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use anyhow::{bail, Result};
use colored::Colorize;
use url::Url;

use crate::session::{Session, SessionVerification};
Expand All @@ -7,8 +8,8 @@ pub fn verify(session: &Session, address: &Url) -> Result<()> {
println!("[*] Verifying session token...");
let verification = verify_inner(session, address)?;

println!("[*] Hello, {}!", verification.name);
println!("[*] Session token is valid.");
println!("[*] Hello, {}!", verification.name.underline());
println!("{}", "[*] Session token is valid.".green());
Ok(())
}

Expand Down
2 changes: 1 addition & 1 deletion scaffold/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fn main() -> Result<()> {
SubCommand::Token { token } => {
commands::token::token(&session(args.token).ok(), token, &args.address)?
}
SubCommand::Init { day, year } => commands::init::init(&session(args.token)?, day, year)?,
_ => todo!(),
}

Ok(())
Expand Down
Loading

0 comments on commit f05148d

Please sign in to comment.