@@ -36,61 +36,13 @@ fn from_args() -> Result<(), String> {
3636 store_default_models ( & mut ses) ?;
3737
3838 let matches = match_args ( ) ;
39-
40- if match_model_list ( & mut ses, & matches) ? {
41- return Ok ( ( ) ) ; // Exit after showing model list
42- }
43-
44- match_repo_args ( & mut ses, & matches) ?;
45-
46- if match_model_subcommand ( & mut ses, & matches) ? {
47- return Ok ( ( ) ) ; // Exit after model subcommand
48- }
49- match_commit_limit_args ( & mut ses, & matches) ?;
50-
51- let include_remote = !matches. get_flag ( "local" ) ;
52-
53- let reverse_commit_order = matches. get_flag ( "reverse" ) ;
54-
55- ses. svg = matches. get_flag ( "svg" ) ;
56- let compact = !matches. get_flag ( "sparse" ) ;
57- let debug = matches. get_flag ( "debug" ) ;
58- let style = matches
59- . get_one :: < String > ( "style" )
60- . map ( |s| Characters :: from_str ( s) )
61- . unwrap_or_else ( || Ok ( Characters :: thin ( ) ) ) ?;
62-
63- let style = if reverse_commit_order {
64- style. reverse ( )
65- } else {
66- style
67- } ;
68-
69- let model = match_model_opt ( & mut ses, & matches) ?;
70-
71- let format = match_format_args ( & mut ses, & matches) ?;
72-
73- let colored = match_color_args ( & mut ses, & matches) ?;
74-
75- let wrapping = match_wrap_args ( & mut ses, & matches) ?;
76-
77- let settings = Settings {
78- reverse_commit_order,
79- debug,
80- colored,
81- compact,
82- include_remote,
83- format,
84- wrapping,
85- characters : style,
86- branch_order : BranchOrder :: ShortestFirst ( true ) ,
87- branches : BranchSettings :: from ( model) . map_err ( |err| err. to_string ( ) ) ?,
88- merge_patterns : MergePatterns :: default ( ) ,
39+ if !configure_session ( & mut ses, & matches) ? {
40+ return Ok ( ( ) ) ; // If the configuration decided session should not start
8941 } ;
9042
9143 run (
9244 ses. repository . unwrap ( ) ,
93- & settings,
45+ ses . settings . as_ref ( ) . unwrap ( ) ,
9446 ses. svg ,
9547 ses. commit_limit ,
9648 )
@@ -176,12 +128,73 @@ fn match_args() -> ArgMatches {
176128 app. get_matches ( )
177129}
178130
131+ /// Return true if session should continue, false if it should exit now
132+ fn configure_session ( ses : & mut Session , matches : & ArgMatches ) -> Result < bool , String > {
133+ // return values
134+ let exit_now = false ;
135+ let run_application = true ;
136+
137+ if match_model_list ( ses, matches) ? {
138+ return Ok ( exit_now) ; // Exit after showing model list
139+ }
140+
141+ match_repo_args ( ses, matches) ?;
142+
143+ if match_model_subcommand ( ses, matches) ? {
144+ return Ok ( exit_now) ; // Exit after model subcommand
145+ }
146+ match_commit_limit_args ( ses, matches) ?;
147+
148+ let include_remote = !matches. get_flag ( "local" ) ;
149+
150+ let reverse_commit_order = matches. get_flag ( "reverse" ) ;
151+
152+ ses. svg = matches. get_flag ( "svg" ) ;
153+ let compact = !matches. get_flag ( "sparse" ) ;
154+ let debug = matches. get_flag ( "debug" ) ;
155+ let style = matches
156+ . get_one :: < String > ( "style" )
157+ . map ( |s| Characters :: from_str ( s) )
158+ . unwrap_or_else ( || Ok ( Characters :: thin ( ) ) ) ?;
159+
160+ let style = if reverse_commit_order {
161+ style. reverse ( )
162+ } else {
163+ style
164+ } ;
165+
166+ let model = match_model_opt ( ses, matches) ?;
167+
168+ let format = match_format_args ( ses, matches) ?;
169+
170+ let colored = match_color_args ( ses, matches) ?;
171+
172+ let wrapping = match_wrap_args ( ses, matches) ?;
173+
174+ let settings = Settings {
175+ reverse_commit_order,
176+ debug,
177+ colored,
178+ compact,
179+ include_remote,
180+ format,
181+ wrapping,
182+ characters : style,
183+ branch_order : BranchOrder :: ShortestFirst ( true ) ,
184+ branches : BranchSettings :: from ( model) . map_err ( |err| err. to_string ( ) ) ?,
185+ merge_patterns : MergePatterns :: default ( ) ,
186+ } ;
187+ ses. settings = Some ( settings) ;
188+
189+ Ok ( run_application)
190+ }
191+
179192struct Session {
180193 // models related fields
181194 models_dir : PathBuf ,
182195
183196 // Settings related fields
184- // TODO
197+ pub settings : Option < Settings > ,
185198
186199 // Other fields
187200 pub repository : Option < Repository > ,
@@ -196,7 +209,7 @@ impl Session {
196209 models_dir : PathBuf :: new ( ) ,
197210
198211 // Settings related fields
199- // TODO
212+ settings : None ,
200213
201214 // Other fields
202215 repository : None ,
0 commit comments