11use crate :: webserver:: content_security_policy:: ContentSecurityPolicyTemplate ;
22use crate :: webserver:: routing:: RoutingConfig ;
33use anyhow:: Context ;
4- use clap :: Parser ;
4+ use crate :: cli :: arguments :: { Cli , parse_cli } ;
55use config:: Config ;
66use openidconnect:: IssuerUrl ;
77use percent_encoding:: AsciiSet ;
@@ -10,34 +10,6 @@ use serde::{Deserialize, Deserializer, Serialize};
1010use std:: net:: { SocketAddr , ToSocketAddrs } ;
1111use std:: path:: { Path , PathBuf } ;
1212
13- #[ derive( Parser ) ]
14- #[ clap( author, version, about, long_about = None ) ]
15- pub struct Cli {
16- /// The directory where the .sql files are located.
17- #[ clap( short, long) ]
18- pub web_root : Option < PathBuf > ,
19- /// The directory where the sqlpage.json configuration, the templates, and the migrations are located.
20- #[ clap( short = 'd' , long) ]
21- pub config_dir : Option < PathBuf > ,
22- /// The path to the configuration file.
23- #[ clap( short = 'c' , long) ]
24- pub config_file : Option < PathBuf > ,
25-
26- /// Subcommands for additional functionality.
27- #[ clap( subcommand) ]
28- pub command : Option < Commands > ,
29- }
30-
31- /// Enum for subcommands.
32- #[ derive( Parser ) ]
33- pub enum Commands {
34- /// Create a new migration file.
35- CreateMigration {
36- /// Name of the migration.
37- migration_name : String ,
38- } ,
39- }
40-
4113#[ cfg( not( feature = "lambda-web" ) ) ]
4214const DEFAULT_DATABASE_FILE : & str = "sqlpage.db" ;
4315
@@ -154,8 +126,8 @@ impl AppConfig {
154126 }
155127}
156128
157- pub fn load_from_cli ( ) -> anyhow:: Result < AppConfig > {
158- let cli = Cli :: parse ( ) ;
129+ pub fn load_config ( ) -> anyhow:: Result < AppConfig > {
130+ let cli = parse_cli ( ) ? ;
159131 AppConfig :: from_cli ( & cli)
160132}
161133
@@ -654,23 +626,6 @@ mod test {
654626 ) ;
655627 }
656628
657- #[ test]
658- fn test_cli_argument_parsing ( ) {
659- let cli = Cli :: parse_from ( [
660- "sqlpage" ,
661- "--web-root" ,
662- "/path/to/web" ,
663- "--config-dir" ,
664- "/path/to/config" ,
665- "--config-file" ,
666- "/path/to/config.json" ,
667- ] ) ;
668-
669- assert_eq ! ( cli. web_root, Some ( PathBuf :: from( "/path/to/web" ) ) ) ;
670- assert_eq ! ( cli. config_dir, Some ( PathBuf :: from( "/path/to/config" ) ) ) ;
671- assert_eq ! ( cli. config_file, Some ( PathBuf :: from( "/path/to/config.json" ) ) ) ;
672- }
673-
674629 #[ test]
675630 fn test_sqlpage_prefixed_env_variable_parsing ( ) {
676631 let _lock = ENV_LOCK
0 commit comments