File tree Expand file tree Collapse file tree 5 files changed +103
-17
lines changed Expand file tree Collapse file tree 5 files changed +103
-17
lines changed Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ lto = true
16
16
[dependencies ]
17
17
atty = { version = " 0.2" }
18
18
chrono = { version = " 0.4" }
19
+ schemars = " 0.9"
19
20
serde = { version = " 1.0" , features = [" derive" ] }
20
21
serde_json = { version = " 1.0" , features = [" preserve_order" ] }
21
22
thiserror = { version = " 2.0" }
Original file line number Diff line number Diff line change 1
1
// Copyright (c) Microsoft Corporation.
2
2
// Licensed under the MIT License.
3
3
4
+ use schemars:: schema_for;
5
+ use serde_json:: to_string_pretty;
6
+ use std:: { env:: args, process:: exit} ;
7
+
4
8
use crate :: export:: invoke_export;
9
+ use crate :: parser:: SshdConfigParser ;
5
10
6
11
mod error;
7
12
mod export;
@@ -10,6 +15,22 @@ mod parser;
10
15
mod util;
11
16
12
17
fn main ( ) {
18
+
19
+ // TODO: add support for other commands and use clap for argument parsing
20
+ let args: Vec < String > = args ( ) . collect ( ) ;
21
+
22
+ if args. len ( ) != 2 || ( args[ 1 ] != "export" && args[ 1 ] != "schema" ) {
23
+ eprintln ! ( "Usage: {} <export|schema>" , args[ 0 ] ) ;
24
+ exit ( 1 ) ;
25
+ }
26
+
27
+ if args[ 1 ] == "schema" {
28
+ // for dsc tests on linux/mac
29
+ let schema = schema_for ! ( SshdConfigParser ) ;
30
+ println ! ( "{}" , to_string_pretty( & schema) . unwrap( ) ) ;
31
+ return ;
32
+ }
33
+
13
34
// only supports export for sshdconfig for now
14
35
match invoke_export ( ) {
15
36
Ok ( result) => {
Original file line number Diff line number Diff line change 1
1
// Copyright (c) Microsoft Corporation.
2
2
// Licensed under the MIT License.
3
3
4
+ use schemars:: JsonSchema ;
4
5
use serde_json:: { Map , Value } ;
5
6
use tree_sitter:: Parser ;
6
7
7
8
use crate :: error:: SshdConfigError ;
8
9
use crate :: metadata:: { MULTI_ARG_KEYWORDS , REPEATABLE_KEYWORDS } ;
9
10
11
+ #[ derive( Debug , JsonSchema ) ]
10
12
pub struct SshdConfigParser {
11
13
map : Map < String , Value >
12
14
}
@@ -236,11 +238,10 @@ mod tests {
236
238
}
237
239
238
240
#[ test]
239
- fn err ( ) {
241
+ fn empty_string_is_ok ( ) {
240
242
let code = r#"
241
243
"# ;
242
244
let result = parse_text_to_map ( code) ;
243
- println ! ( "{result:?}" ) ;
244
245
assert ! ( result. is_ok( ) ) ;
245
246
}
246
247
}
Original file line number Diff line number Diff line change 1
1
{
2
- "manifestVersion" : " 1.0" ,
3
- "configuration" : {
4
- "get" : {
2
+ "$schema" : " https://aka.ms/dsc/schemas/v3/bundled/resource/manifest.json" ,
3
+ "type" : " Microsoft.Windows.OpenSSH.SSHD/sshd_config" ,
4
+ "description" : " Manage SSH Server Configuration" ,
5
+ "version" : " 0.1.0" ,
6
+ "export" : {
7
+ "executable" : " sshdconfig" ,
8
+ "args" : [
9
+ " export"
10
+ ]
11
+ },
12
+ "schema" : {
13
+ "command" : {
5
14
"executable" : " sshdconfig" ,
6
- "args" : [ " get" ],
7
- "acceptStdin" : true
8
- },
9
- "set" : {
10
- "executable" : " sshdconfig" ,
11
- "args" : [ " set" ],
12
- "acceptStdin" : true
13
- },
14
- "test" : {
15
- "executable" : " sshdconfig" ,
16
- "args" : [ " test" ],
17
- "acceptStdin" : true
15
+ "args" : [
16
+ " schema"
17
+ ]
18
18
}
19
19
}
20
20
}
You can’t perform that action at this time.
0 commit comments