Skip to content

Commit bb31fac

Browse files
authored
Merge pull request #958 from tgauth/add-sshdconfig-tracing
sshdconfig: add tracing and update constants
2 parents c2d08ed + 4b43f12 commit bb31fac

File tree

11 files changed

+254
-52
lines changed

11 files changed

+254
-52
lines changed

sshdconfig/Cargo.lock

Lines changed: 99 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sshdconfig/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@ lto = true
1717
atty = { version = "0.2" }
1818
chrono = { version = "0.4" }
1919
clap = { version = "4.5", features = ["derive"] }
20+
crossterm = { version = "0.27" }
2021
rust-i18n = { version = "3.1" }
2122
schemars = "0.8"
2223
serde = { version = "1.0", features = ["derive"] }
2324
serde_json = { version = "1.0", features = ["preserve_order"] }
2425
thiserror = { version = "2.0" }
2526
tracing = "0.1.37"
26-
tracing-subscriber = "0.3.17"
27+
tracing-subscriber = { version = "0.3.17", features = ["ansi", "env-filter", "json"] }
2728
tree-sitter = "0.25"
2829
tree-sitter-rust = "0.24"
2930
tree-sitter-ssh-server-config = { path = "../tree-sitter-ssh-server-config" }

sshdconfig/locales/en-us.toml

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,18 @@ parseInt = "Parse Integer"
1414
registry = "Registry"
1515

1616
[get]
17+
debugSetting = "Get setting:"
1718
defaultShellCmdOptionMustBeString = "cmdOption must be a string"
1819
defaultShellEscapeArgsMustBe0Or1 = "'%{input}' must be a 0 or 1"
1920
defaultShellEscapeArgsMustBeDWord = "escapeArguments must be a DWord"
2021
defaultShellMustBeString = "shell must be a string"
2122
notImplemented = "get not yet implemented for Microsoft.OpenSSH.SSHD/sshd_config"
2223
windowsOnly = "Microsoft.OpenSSH.SSHD/Windows is only applicable to Windows"
2324

24-
[set]
25-
failedToParseInput = "failed to parse input as DefaultShell with error: '%{error}'"
26-
shellPathDoesNotExist = "shell path does not exist: '%{shell}'"
27-
shellPathMustNotBeRelative = "shell path must not be relative"
25+
[main]
26+
export = "Export"
27+
schema = "Schema command:"
28+
set = "Set command: '%{input}'"
2829

2930
[parser]
3031
failedToParse = "failed to parse: '%{input}'"
@@ -33,13 +34,22 @@ failedToParseChildNode = "failed to parse child node: '%{input}'"
3334
failedToParseNode = "failed to parse '%{input}'"
3435
failedToParseRoot = "failed to parse root: '%{input}'"
3536
invalidConfig = "invalid config: '%{input}'"
37+
invalidMultiArgNode = "multi-arg node '%{input}' is not valid"
3638
invalidValue = "operator is an invalid value for node"
3739
keyNotFound = "key '%{key}' not found"
3840
keyNotRepeatable = "key '%{key}' is not repeatable"
39-
missingKeyInChildNode = "missing key in child node: '%{input}'"
41+
keywordDebug = "Parsing keyword: '%{text}'"
4042
missingValueInChildNode = "missing value in child node: '%{input}'"
43+
missingKeyInChildNode = "missing key in child node: '%{input}'"
44+
valueDebug = "Parsed argument value:"
4145
unknownNode = "unknown node: '%{kind}'"
4246
unknownNodeType = "unknown node type: '%{node}'"
4347

48+
[set]
49+
failedToParseInput = "failed to parse input as DefaultShell with error: '%{error}'"
50+
shellPathDoesNotExist = "shell path does not exist: '%{shell}'"
51+
shellPathMustNotBeRelative = "shell path must not be relative"
52+
4453
[util]
4554
sshdElevation = "elevated security context required"
55+
tracingInitError = "Failed to initialize tracing"

sshdconfig/src/get.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,19 @@ use {
88
crate::metadata::windows::{DEFAULT_SHELL, DEFAULT_SHELL_CMD_OPTION, DEFAULT_SHELL_ESCAPE_ARGS, REGISTRY_PATH},
99
};
1010

11+
use rust_i18n::t;
12+
use tracing::debug;
13+
1114
use crate::args::Setting;
1215
use crate::error::SshdConfigError;
13-
use rust_i18n::t;
1416

1517
/// Invoke the get command.
1618
///
1719
/// # Errors
1820
///
1921
/// This function will return an error if the desired settings cannot be retrieved.
2022
pub fn invoke_get(setting: &Setting) -> Result<(), SshdConfigError> {
23+
debug!("{}: {:?}", t!("get.debugSetting").to_string(), setting);
2124
match *setting {
2225
Setting::SshdConfig => Err(SshdConfigError::NotImplemented(t!("get.notImplemented").to_string())),
2326
Setting::WindowsGlobal => get_default_shell()

sshdconfig/src/main.rs

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@
22
// Licensed under the MIT License.
33

44
use clap::{Parser};
5-
use rust_i18n::i18n;
5+
use rust_i18n::{i18n, t};
66
use schemars::schema_for;
7+
use std::process::exit;
8+
use tracing::{debug, error};
79

810
use args::{Args, Command, DefaultShell, Setting};
911
use export::invoke_export;
1012
use get::invoke_get;
1113
use parser::SshdConfigParser;
1214
use set::invoke_set;
15+
use util::enable_tracing;
1316

1417
mod args;
1518
mod error;
@@ -22,14 +25,24 @@ mod util;
2225

2326
i18n!("locales", fallback = "en-us");
2427

28+
const EXIT_SUCCESS: i32 = 0;
29+
const EXIT_FAILURE: i32 = 1;
30+
2531
fn main() {
32+
enable_tracing();
33+
2634
let args = Args::parse();
2735

2836
let result = match &args.command {
29-
Command::Export => invoke_export(),
30-
Command::Get { setting } => invoke_get(setting),
31-
Command::Set { input } => invoke_set(input),
37+
Command::Export => {
38+
debug!("{}", t!("main.export").to_string());
39+
invoke_export()
40+
},
41+
Command::Get { setting } => {
42+
invoke_get(setting)
43+
},
3244
Command::Schema { setting } => {
45+
debug!("{}; {:?}", t!("main.schema").to_string(), setting);
3346
let schema = match setting {
3447
Setting::SshdConfig => {
3548
schema_for!(SshdConfigParser)
@@ -40,11 +53,17 @@ fn main() {
4053
};
4154
println!("{}", serde_json::to_string(&schema).unwrap());
4255
Ok(())
43-
}
56+
},
57+
Command::Set { input } => {
58+
debug!("{}", t!("main.set", input = input).to_string());
59+
invoke_set(input)
60+
},
4461
};
4562

4663
if let Err(e) = result {
47-
eprintln!("{e}");
48-
std::process::exit(1);
64+
error!("{e}");
65+
exit(EXIT_FAILURE);
4966
}
67+
68+
exit(EXIT_SUCCESS);
5069
}

0 commit comments

Comments
 (0)