This repository was archived by the owner on Sep 10, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +17
-3
lines changed Expand file tree Collapse file tree 1 file changed +17
-3
lines changed Original file line number Diff line number Diff line change @@ -90,7 +90,13 @@ pub(super) struct Options {
90
90
#[ derive( Parser , Debug ) ]
91
91
enum Subcommand {
92
92
/// Dump the current config as YAML
93
- Dump ,
93
+ Dump {
94
+ /// The path to the config file to dump
95
+ ///
96
+ /// If not specified, the config will be written to stdout
97
+ #[ clap( short, long) ]
98
+ output : Option < Utf8PathBuf > ,
99
+ } ,
94
100
95
101
/// Check a config file
96
102
Check ,
@@ -121,12 +127,20 @@ impl Options {
121
127
pub async fn run ( self , root : & super :: Options ) -> anyhow:: Result < ( ) > {
122
128
use Subcommand as SC ;
123
129
match self . subcommand {
124
- SC :: Dump => {
130
+ SC :: Dump { output } => {
125
131
let _span = info_span ! ( "cli.config.dump" ) . entered ( ) ;
126
132
127
133
let config: RootConfig = root. load_config ( ) ?;
134
+ let config = serde_yaml:: to_string ( & config) ?;
128
135
129
- serde_yaml:: to_writer ( std:: io:: stdout ( ) , & config) ?;
136
+ if let Some ( output) = output {
137
+ info ! ( "Writing configuration to {output:?}" ) ;
138
+ let mut file = tokio:: fs:: File :: create ( output) . await ?;
139
+ file. write_all ( config. as_bytes ( ) ) . await ?;
140
+ } else {
141
+ info ! ( "Writing configuration to standard output" ) ;
142
+ tokio:: io:: stdout ( ) . write_all ( config. as_bytes ( ) ) . await ?;
143
+ }
130
144
}
131
145
132
146
SC :: Check => {
You can’t perform that action at this time.
0 commit comments