@@ -49,35 +49,43 @@ pub struct CliArgs {
4949 /// Debug errors with more precise information.
5050 #[ arg( short, long, default_value_t = false ) ]
5151 debug : bool ,
52+ /// Generate with a given random seed
53+ #[ arg( short, long) ]
54+ seed : Option < u64 > ,
5255}
5356
5457impl CliArgs {
5558 /// Check if the sequence of commands given are meaningful
5659 fn check_arguments ( & self ) -> Res < ( ) > {
5760 let provided = self . list_provided ( ) ;
5861
59- Err (
60- if self . list
61- && let Some ( other) = find_other_than ( & provided, & [ "list" , "user" , "type" ] )
62- {
63- Error :: ConflictingArgs ( "list" , other)
64- } else if self . interactive
65- && let Some ( other) = find_other_than ( & provided, & [ "interactive" , "user" , "type" ] )
66- {
67- Error :: ConflictingArgs ( "interactive" , other)
68- } else if self . values . is_some ( )
69- && let Some ( other) = find_other_than ( & provided, & [ "values" , "user" , "type" ] )
70- {
71- Error :: ConflictingArgs ( "values" , other)
72- } else if self . json . is_some ( ) && self . schema_file != "schema.json" {
73- Error :: ConflictingArgs ( "json" , "schema" )
74- } else {
75- return Ok ( ( ) ) ;
76- } ,
77- )
62+ let conflicting_arguments = if self . list
63+ && let Some ( other) = find_other_than ( & provided, & [ "list" , "user" , "type" ] )
64+ {
65+ ( "list" , other)
66+ } else if self . interactive
67+ && let Some ( other) = find_other_than ( & provided, & [ "interactive" , "user" , "type" ] )
68+ {
69+ ( "interactive" , other)
70+ } else if self . values . is_some ( )
71+ && let Some ( other) = find_other_than ( & provided, & [ "values" , "user" , "type" ] )
72+ {
73+ ( "values" , other)
74+ } else if self . json . is_some ( ) && self . schema_file != "schema.json" {
75+ ( "json" , "schema" )
76+ } else if self . seed . is_some ( ) && self . list {
77+ ( "seed" , "list" )
78+ } else {
79+ return Ok ( ( ) ) ;
80+ } ;
81+
82+ Err ( Error :: ConflictingArgs ( conflicting_arguments. 0 , conflicting_arguments. 1 ) )
7883 }
7984
80- /// Count the number of provided arguments
85+ /// Count the number of provided arguments that may invalidate others
86+ ///
87+ /// This excludes flags, like `--debug`, or options that can always be
88+ /// passed, like `--seed`.
8189 fn list_provided ( & self ) -> Vec < & ' static str > {
8290 let mut provided = Vec :: with_capacity ( 5 ) ;
8391
@@ -136,7 +144,7 @@ impl CliArgs {
136144 /// Run the generation based on the parsed CLI arguments.
137145 fn run ( self ) -> Res < String > {
138146 self . check_arguments ( ) ?;
139- let mut data = Data :: new ( self . user_defined ) ?;
147+ let mut data = Data :: new ( self . user_defined , self . seed ) ?;
140148
141149 if let Some ( data_type) = self . values {
142150 return data. values ( & data_type) ;
0 commit comments