@@ -60,13 +60,25 @@ struct CliOptions {
60
60
verbose : bool ,
61
61
write_mode : Option < WriteMode > ,
62
62
file_lines : FileLines , // Default is all lines in all files.
63
+ unstable_features : bool ,
63
64
}
64
65
65
66
impl CliOptions {
66
67
fn from_matches ( matches : & Matches ) -> FmtResult < CliOptions > {
67
68
let mut options = CliOptions :: default ( ) ;
68
69
options. skip_children = matches. opt_present ( "skip-children" ) ;
69
70
options. verbose = matches. opt_present ( "verbose" ) ;
71
+ let unstable_features = matches. opt_present ( "unstable_features" ) ;
72
+ let rust_nightly = option_env ! ( "CFG_RELEASE_CHANNEL" )
73
+ . map ( |c| c == "nightly" )
74
+ . unwrap_or ( false ) ;
75
+ if unstable_features && !rust_nightly {
76
+ return Err ( FmtError :: from ( format ! (
77
+ "Unstable features are only available on Nightly channel"
78
+ ) ) ) ;
79
+ } else {
80
+ options. unstable_features = unstable_features;
81
+ }
70
82
71
83
if let Some ( ref write_mode) = matches. opt_str ( "write-mode" ) {
72
84
if let Ok ( write_mode) = WriteMode :: from_str ( write_mode) {
@@ -89,6 +101,7 @@ impl CliOptions {
89
101
config. set ( ) . skip_children ( self . skip_children ) ;
90
102
config. set ( ) . verbose ( self . verbose ) ;
91
103
config. set ( ) . file_lines ( self . file_lines ) ;
104
+ config. set ( ) . unstable_features ( self . unstable_features ) ;
92
105
if let Some ( write_mode) = self . write_mode {
93
106
config. set ( ) . write_mode ( write_mode) ;
94
107
}
@@ -123,7 +136,7 @@ fn make_opts() -> Options {
123
136
opts. optflag (
124
137
"" ,
125
138
"unstable-features" ,
126
- "Enables unstable features. Only available in rust nightlies " ,
139
+ "Enables unstable features. Only available on nightly channel " ,
127
140
) ;
128
141
129
142
opts. optflag (
@@ -157,7 +170,6 @@ fn make_opts() -> Options {
157
170
"JSON" ,
158
171
) ;
159
172
160
-
161
173
opts
162
174
}
163
175
0 commit comments