Initial commit
This commit is contained in:
80
src/main.rs
Normal file
80
src/main.rs
Normal file
@ -0,0 +1,80 @@
|
||||
use serde_derive::Deserialize;
|
||||
use toml;
|
||||
|
||||
// Example TOML file
|
||||
/*
|
||||
[metadata]
|
||||
name = "example"
|
||||
version = "0.1.0"
|
||||
description = "Example package"
|
||||
homepage = "https://example.com"
|
||||
url = "https://example.com/example-0.1.0-linux-amd64.tar.gz"
|
||||
license = "MIT"
|
||||
|
||||
# Uses XDG Base Directory Specification
|
||||
# Except bin, which just goes in $HOME/.local/bin
|
||||
[install]
|
||||
bin = ["example"]
|
||||
config = ["config.toml"]
|
||||
share = ["data"]
|
||||
|
||||
[update.check]
|
||||
type = "github"
|
||||
checkver = "https://example.com/checkver"
|
||||
regex = "v([0-9]+\\.[0-9]+\\.[0-9]+)"
|
||||
|
||||
[update.template]
|
||||
url = "https://example.com/$version-$os-$arch.tar.gz"
|
||||
*/
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct Manifest {
|
||||
metadata: Metadata,
|
||||
install: Install,
|
||||
update: Update,
|
||||
}
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct Metadata {
|
||||
name: String,
|
||||
version: String,
|
||||
description: String,
|
||||
homepage: String,
|
||||
url: String,
|
||||
license: String,
|
||||
}
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct Install {
|
||||
bin: Vec<String>,
|
||||
config: Vec<String>,
|
||||
share: Vec<String>,
|
||||
}
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct Update {
|
||||
check: Check,
|
||||
template: Template,
|
||||
}
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct Check {
|
||||
type_: String,
|
||||
checkver: String,
|
||||
regex: String,
|
||||
}
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct Template {
|
||||
url: String,
|
||||
}
|
||||
|
||||
// Load TOML file from first argument
|
||||
// Then parse it into a Manifest struct
|
||||
// Then print the struct
|
||||
|
||||
fn main() {
|
||||
let args: Vec<String> = std::env::args().collect();
|
||||
if args.len() != 2 {
|
||||
eprintln!("Usage: {} <file>", args[0]);
|
||||
std::process::exit(1);
|
||||
}
|
||||
let file = std::fs::read_to_string(&args[1]).unwrap();
|
||||
let manifest: Manifest = toml::from_str(&file).unwrap();
|
||||
println!("{:#?}", manifest);
|
||||
}
|
Reference in New Issue
Block a user