Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace Python script w/ Cargo script. #109

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added .data/.gitkeep
Empty file.
Empty file added .data/active.toml
Empty file.
Empty file added .data/stars.toml
Empty file.
884 changes: 0 additions & 884 deletions languages.json

This file was deleted.

628 changes: 628 additions & 0 deletions languages.toml

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions requirements.txt

This file was deleted.

88 changes: 88 additions & 0 deletions update.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#!/usr/bin/env -S cargo +nightly -Zscript
```cargo
[dependencies]
clap = { version = "4.4", features = ["derive"] }
toml = { version = "0.8" }
```

use clap::Parser;
use std::process::ExitCode;
use std::fs::read_to_string;
use std::error::Error;
use toml::Table;
use toml::from_str;

#[derive(Parser, Debug)]
#[clap(version)]
struct Args {
#[arg(short = 'u')]
update: bool,

#[arg(short = 'g')]
generate: bool,
}

fn main() -> ExitCode {
let args = Args::parse();

return match (args.update, args.generate) {
(true, true) => {
eprintln!("error: can specify only one of --update and --generate");
ExitCode::FAILURE
}
(false, false) => {
eprintln!("error: must specify one of --update or --generate");
ExitCode::FAILURE
}
(true, false) => if let Err(err) = update() {
eprintln!("error: {}", err);
ExitCode::FAILURE
} else {
ExitCode::SUCCESS
},
(false, true) => if let Err(err) = generate() {
eprintln!("error: {}", err);
ExitCode::FAILURE
} else {
ExitCode::SUCCESS
},
}

}

/// Update the cached metadata.
fn update() -> Result<(), Box<dyn Error>> {
/*
The intent of this function is that it will read
the `languages.toml` file, then filter down to the
ones that are on GitHub and update the metadata
file, found at `.data/stars.toml` with star data
based on the GitHub API responses, same deal with
`.data/active.toml`.
*/

let langs = toml_from_file("languages.toml")?;

Ok(())
}

/// Regenerate the README.
fn generate() -> Result<(), Box<dyn Error>> {
/*
This takes the list of languages from
`languages.toml`, and also loads `.data/stars.toml`,
and uses the data from both to generate a new
`README.md` file.
*/

let langs = toml_from_file("languages.toml")?;

Ok(())
}

/// Read the TOML data from a file.
fn toml_from_file(file: &str) -> Result<Table, Box<dyn Error>> {
Ok(from_str(&read_to_string(file)?)?)
}


File renamed without changes.