-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from SteveL-MSFT/config-args
Implement args parsing
- Loading branch information
Showing
4 changed files
with
235 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# `config` command for using DSC resources | ||
|
||
## DESCRIPTION | ||
|
||
The `config` command is used to discover and invoke DSC resources. | ||
|
||
## Usage | ||
|
||
Usage: config [subcommand] [options] | ||
Subcommands: | ||
list [filter] - list all resources, optional filter | ||
get <resource> - invoke `get` on a resource | ||
set <resource> - invoke `set` on a resource | ||
test <resource> - invoke `test` on a resource | ||
flushcache - flush the resource cache | ||
Options: | ||
-h, --help | ||
-n, --nocache - don't use the cache and force a new discovery |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,41 @@ | ||
use args::*; | ||
use atty::Stream; | ||
use std::process::exit; | ||
use std::{env, io}; | ||
|
||
pub mod args; | ||
pub mod discovery; | ||
pub mod dscresources; | ||
pub mod dscerror; | ||
|
||
use args::*; | ||
pub const EXIT_INVALID_ARGS: i32 = 1; | ||
pub const EXIT_INVALID_INPUT: i32 = 2; | ||
|
||
fn main() { | ||
let args = Args::new(); | ||
let args = Args::new(&mut env::args(), &mut io::stdin(), atty::is(Stream::Stdin)); | ||
match args.subcommand { | ||
SubCommand::List => { | ||
// perform discovery | ||
println!("List"); | ||
println!("List {}", args.filter); | ||
} | ||
SubCommand::Get => { | ||
// perform discovery | ||
println!("Get"); | ||
println!("Get {}: {}", args.resource, args.stdin); | ||
} | ||
SubCommand::Set => { | ||
// perform discovery | ||
println!("Set"); | ||
println!("Set {}: {}", args.resource, args.stdin); | ||
} | ||
SubCommand::Test => { | ||
// perform discovery | ||
println!("Test"); | ||
println!("Test {}: {}", args.resource, args.stdin); | ||
} | ||
SubCommand::FlushCache => { | ||
println!("FlushCache"); | ||
} | ||
_ => { | ||
eprintln!("Invalid subcommand"); | ||
exit(EXIT_INVALID_ARGS); | ||
} | ||
} | ||
} |