File tree Expand file tree Collapse file tree 2 files changed +23
-8
lines changed Expand file tree Collapse file tree 2 files changed +23
-8
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
8
8
## [ Unreleased]
9
9
10
+ ### Added
11
+
12
+ - ` try_create ` and ` validate ` functions to the type generated by the ` pasfmt_config! ` macro.
13
+
10
14
### Fixed
11
15
12
16
- Lexing of conditional directive expressions containing compiler directives, comments, or strings.
Original file line number Diff line number Diff line change @@ -30,18 +30,29 @@ macro_rules! pasfmt_config {
30
30
config: PasFmtConfiguration ,
31
31
}
32
32
impl $type_name {
33
- pub fn create( ) -> PasFmtConfiguration {
34
- let parsed = Self :: parse( ) ;
35
- let mut cmd = Self :: command( ) ;
36
- if matches!( parsed. config. mode( ) , FormatMode :: Files ) && parsed. config. is_stdin( ) {
37
- cmd. error(
33
+ #[ allow( unused) ]
34
+ pub fn validate( self ) -> Result <PasFmtConfiguration , clap:: Error > {
35
+ if matches!( self . config. mode( ) , FormatMode :: Files ) && self . config. is_stdin( ) {
36
+ return Err ( Self :: command( ) . error(
38
37
ErrorKind :: ArgumentConflict ,
39
38
"Files mode not supported when reading from stdin." ,
40
- )
41
- . exit( ) ;
39
+ ) ) ;
42
40
}
43
41
44
- parsed. config
42
+ Ok ( self . config)
43
+ }
44
+
45
+ #[ allow( unused) ]
46
+ pub fn try_create( ) -> Result <PasFmtConfiguration , clap:: Error > {
47
+ Self :: try_parse( ) ?. validate( )
48
+ }
49
+
50
+ #[ allow( unused) ]
51
+ pub fn create( ) -> PasFmtConfiguration {
52
+ match Self :: try_create( ) {
53
+ Ok ( config) => config,
54
+ Err ( err) => err. exit( ) ,
55
+ }
45
56
}
46
57
}
47
58
} ;
You can’t perform that action at this time.
0 commit comments