@@ -180,24 +180,10 @@ enum Cmd {
180
180
pv : ProductVersion ,
181
181
} ,
182
182
183
- /// Creates a patchable.toml for a given product version
183
+ /// Creates patchable.toml configuration files
184
184
Init {
185
- #[ clap( flatten) ]
186
- pv : ProductVersion ,
187
-
188
- /// The upstream commit-ish (such as druid-28.0.0) that the patch series applies to
189
- ///
190
- /// Refs (such as tags and branches) will be resolved to commit IDs.
191
- #[ clap( long) ]
192
- base : String ,
193
-
194
- /// Mirror the product version to the default mirror repository
195
- #[ clap( long) ]
196
- mirror : bool ,
197
-
198
- /// Use SSH for git operations
199
- #[ clap( long) ]
200
- ssh : bool ,
185
+ #[ clap( subcommand) ]
186
+ init_type : InitCmd ,
201
187
} ,
202
188
203
189
/// Shows the patch directory for a given product version
@@ -218,6 +204,41 @@ enum Cmd {
218
204
ImagesDir ,
219
205
}
220
206
207
+ #[ derive( clap:: Parser ) ]
208
+ enum InitCmd {
209
+ /// Creates a patchable.toml for a given product
210
+ Product {
211
+ /// The product name slug (such as druid)
212
+ product : String ,
213
+ /// The upstream repository URL (e.g. https://github.com/apache/druid.git)
214
+ #[ clap( long) ]
215
+ upstream : String ,
216
+ /// The default mirror repository URL (e.g. https://github.com/stackabletech/druid.git)
217
+ #[ clap( long) ]
218
+ default_mirror : Option < String > ,
219
+ } ,
220
+
221
+ /// Creates a patchable.toml for a given product version
222
+ Version {
223
+ #[ clap( flatten) ]
224
+ pv : ProductVersion ,
225
+
226
+ /// The upstream commit-ish (such as druid-28.0.0) that the patch series applies to
227
+ ///
228
+ /// Refs (such as tags and branches) will be resolved to commit IDs.
229
+ #[ clap( long) ]
230
+ base : String ,
231
+
232
+ /// Mirror the product version to the default mirror repository
233
+ #[ clap( long) ]
234
+ mirror : bool ,
235
+
236
+ /// Use SSH for git operations
237
+ #[ clap( long) ]
238
+ ssh : bool ,
239
+ } ,
240
+ }
241
+
221
242
#[ derive( Debug , Snafu ) ]
222
243
pub enum Error {
223
244
#[ snafu( display( "failed to configure git logging" ) ) ]
@@ -475,10 +496,61 @@ fn main() -> Result<()> {
475
496
}
476
497
477
498
Cmd :: Init {
478
- pv,
479
- base,
480
- mirror,
481
- ssh,
499
+ init_type :
500
+ InitCmd :: Product {
501
+ product,
502
+ upstream,
503
+ default_mirror,
504
+ } ,
505
+ } => {
506
+ let product_config_path = ProductVersionContext {
507
+ pv : ProductVersion {
508
+ product : product. clone ( ) ,
509
+ version : "" . to_string ( ) ,
510
+ } ,
511
+ images_repo_root,
512
+ }
513
+ . product_config_path ( ) ;
514
+
515
+ tracing:: info!(
516
+ path = ?product_config_path,
517
+ "creating product configuration directory and file"
518
+ ) ;
519
+
520
+ if let Some ( product_config_dir) = product_config_path. parent ( ) {
521
+ std:: fs:: create_dir_all ( product_config_dir) . context ( CreatePatchDirSnafu {
522
+ path : product_config_dir,
523
+ } ) ?;
524
+ }
525
+
526
+ let product_config = ProductConfig {
527
+ upstream,
528
+ default_mirror,
529
+ } ;
530
+
531
+ let config_toml =
532
+ toml:: to_string_pretty ( & product_config) . context ( SerializeConfigSnafu ) ?;
533
+ File :: create_new ( & product_config_path)
534
+ . and_then ( |mut f| f. write_all ( config_toml. as_bytes ( ) ) )
535
+ . context ( SaveConfigSnafu {
536
+ path : & product_config_path,
537
+ } ) ?;
538
+
539
+ tracing:: info!(
540
+ config. path = ?product_config_path,
541
+ product = product,
542
+ "created configuration for product"
543
+ ) ;
544
+ }
545
+
546
+ Cmd :: Init {
547
+ init_type :
548
+ InitCmd :: Version {
549
+ pv,
550
+ base,
551
+ mirror,
552
+ ssh,
553
+ } ,
482
554
} => {
483
555
let ctx = ProductVersionContext {
484
556
pv,
@@ -510,6 +582,7 @@ fn main() -> Result<()> {
510
582
let mirror_url = if mirror {
511
583
let mut mirror_url = config
512
584
. default_mirror
585
+ . filter ( |s| !s. is_empty ( ) )
513
586
. context ( InitMirrorNotConfiguredSnafu ) ?;
514
587
if ssh {
515
588
mirror_url =
@@ -572,6 +645,7 @@ fn main() -> Result<()> {
572
645
std:: fs:: create_dir_all ( config_dir)
573
646
. context ( CreatePatchDirSnafu { path : config_dir } ) ?;
574
647
}
648
+
575
649
let config_toml = toml:: to_string_pretty ( & config) . context ( SerializeConfigSnafu ) ?;
576
650
File :: create_new ( & config_path)
577
651
. and_then ( |mut f| f. write_all ( config_toml. as_bytes ( ) ) )
0 commit comments