From 87d354ab15d3228219b5685df0d7a5a35e9e0e3a Mon Sep 17 00:00:00 2001 From: "Dawid J. Kubis" Date: Fri, 1 Oct 2021 18:26:52 +0200 Subject: [PATCH] Expanded command line arguments, added `-h` text. --- .gitignore | 1 + src/main.rs | 38 +++++++++++++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index e9868bd..2fd4b8e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /target *.swp +test.toml diff --git a/src/main.rs b/src/main.rs index e7a11a9..24cd7b6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,39 @@ +use structopt::StructOpt; +use toml::Value; + +use std::path::PathBuf; +use std::fs::{read_to_string, copy}; + +#[derive(StructOpt, Debug)] +/// structure representing command line arguments +struct Opt { + #[structopt(name = "FILE")] + /// The input file. + /// It contains all the settings related to substitution + toml: PathBuf, + + #[structopt(short, long, default_value = "output")] + /// Output directory. + output: PathBuf, + + #[structopt(short, long)] + /// Template to be processed. + /// if a directory, then all the unspecified + /// files will be copied to the output as well. + template: PathBuf, +} + + fn main() { - println!("Hello, world!"); + // parse command line arguments + let opt = Opt::from_args(); + //println!("{:?}", opt); + + // parse toml + let value = read_to_string(opt.toml) + .unwrap() + .parse::() + .unwrap(); + println!("{:?}", value); + }