Skip to content
Draft
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
1 change: 1 addition & 0 deletions resources/sshdconfig/locales/en-us.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ getInput = "input to get for sshd_config or default shell settings"
exportCompare = "compare exported sshd_config setting to provided input"
exportInput = "input to export from sshd_config"
setInput = "input to set in sshd_config"
setWhatIf = "validate and return the expected state without applying changes"

[canonical_properties]
inputMustBeBoolean = "value of '%{input}' must be true or false"
Expand Down
12 changes: 10 additions & 2 deletions resources/sshdconfig/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub enum TraceLevel {
Warn,
Info,
Debug,
Trace
Trace,
}

#[derive(Parser)]
Expand All @@ -28,7 +28,13 @@ pub struct Args {
pub command: Command,
#[clap(short = 'l', long, help = "Trace level to use", value_enum)]
pub trace_level: Option<TraceLevel>,
#[clap(short = 'f', long, help = "Trace format to use", value_enum, default_value = "json")]
#[clap(
short = 'f',
long,
help = "Trace format to use",
value_enum,
default_value = "json"
)]
pub trace_format: TraceFormat,
}

Expand All @@ -47,6 +53,8 @@ pub enum Command {
input: String,
#[clap(short = 's', long, hide = true)]
setting: Setting,
#[clap(short = 'w', long = "what-if", help = t!("args.setWhatIf").to_string())]
what_if: bool,
},
/// Export `sshd_config`, eventually to be used for repeatable keywords
Export {
Expand Down
28 changes: 15 additions & 13 deletions resources/sshdconfig/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

use clap::{Parser};
use clap::Parser;
use rust_i18n::{i18n, t};
use schemars::schema_for;
use serde_json::Map;
Expand Down Expand Up @@ -43,33 +43,35 @@ fn main() {
Command::Export { input, compare } => {
debug!("{}: {:?}", t!("main.export").to_string(), input);
invoke_export(input.as_ref(), *compare)
},
Command::Get { input, setting } => {
invoke_get(input.as_ref(), setting)
},
}
Command::Get { input, setting } => invoke_get(input.as_ref(), setting),
Command::Schema { setting } => {
debug!("{}; {:?}", t!("main.schema").to_string(), setting);
let schema = match setting {
Setting::SshdConfig => {
schema_for!(SshdConfigParser)
},
}
Setting::SshdConfigRepeat => {
schema_for!(RepeatInput)
},
}
Setting::SshdConfigRepeatList => {
schema_for!(RepeatListInput)
},
}
Setting::WindowsGlobal => {
schema_for!(DefaultShell)
}
};
println!("{}", serde_json::to_string(&schema).unwrap());
Ok(Map::new())
},
Command::Set { input, setting } => {
}
Command::Set {
input,
setting,
what_if,
} => {
debug!("{}", t!("main.set", input = input).to_string());
invoke_set(input, setting)
},
invoke_set(input, setting, *what_if)
}
};

match result {
Expand All @@ -84,7 +86,7 @@ fn main() {
}
}
exit(EXIT_SUCCESS);
},
}
Err(e) => {
error!("{}", e);
exit(EXIT_FAILURE);
Expand Down
Loading
Loading