@@ -108,7 +108,6 @@ pub struct RawConfig {
108
108
109
109
#[ derive( Debug , Clone ) ]
110
110
pub struct Config {
111
- proj : RawConfig ,
112
111
home : RawConfig ,
113
112
}
114
113
@@ -583,10 +582,7 @@ Fetch the server's fingerprint with:
583
582
584
583
impl Config {
585
584
pub fn default_server_name ( & self ) -> Option < & str > {
586
- self . proj
587
- . default_server
588
- . as_deref ( )
589
- . or ( self . home . default_server . as_deref ( ) )
585
+ self . home . default_server . as_deref ( )
590
586
}
591
587
592
588
/// Add a `ServerConfig` to the home configuration.
@@ -645,18 +641,15 @@ impl Config {
645
641
///
646
642
/// Returns the URL of the default server if `server` is `None`.
647
643
///
648
- /// Entries in the project configuration supersede entries in the home configuration.
649
- ///
650
644
/// If `server` is `Some` and is a complete URL,
651
645
/// including protocol and hostname,
652
646
/// returns that URL without accessing the configuration.
653
647
///
654
648
/// Returns an `Err` if:
655
649
/// - `server` is `Some`, but not a complete URL,
656
650
/// and the supplied name does not refer to any server
657
- /// in either the project or the home configuration.
658
- /// - `server` is `None`, but neither the home nor the project configuration
659
- /// has a default server.
651
+ /// in the configuration.
652
+ /// - `server` is `None`, but the configuration does not have a default server.
660
653
pub fn get_host_url ( & self , server : Option < & str > ) -> anyhow:: Result < String > {
661
654
Ok ( format ! ( "{}://{}" , self . protocol( server) ?, self . host( server) ?) )
662
655
}
@@ -665,36 +658,32 @@ impl Config {
665
658
///
666
659
/// Returns the hostname of the default server if `server` is `None`.
667
660
///
668
- /// Entries in the project configuration supersede entries in the home configuration.
669
- ///
670
661
/// If `server` is `Some` and is a complete URL,
671
662
/// including protocol and hostname,
672
663
/// returns that hostname without accessing the configuration.
673
664
///
674
665
/// Returns an `Err` if:
675
666
/// - `server` is `Some`, but not a complete URL,
676
667
/// and the supplied name does not refer to any server
677
- /// in either the project or the home configuration.
678
- /// - `server` is `None`, but neither the home nor the project configuration
679
- /// has a default server.
668
+ /// in the configuration.
669
+ /// - `server` is `None`, but the configuration does not
670
+ /// have a default server.
680
671
pub fn host < ' a > ( & ' a self , server : Option < & ' a str > ) -> anyhow:: Result < & ' a str > {
681
672
if let Some ( server) = server {
682
673
if contains_protocol ( server) {
683
674
Ok ( host_or_url_to_host_and_protocol ( server) . 0 )
684
675
} else {
685
- self . proj . host ( server ) . or_else ( |_| self . home . host ( server) )
676
+ self . home . host ( server)
686
677
}
687
678
} else {
688
- self . proj . default_host ( ) . or_else ( |_| self . home . default_host ( ) )
679
+ self . home . default_host ( )
689
680
}
690
681
}
691
682
692
683
/// Get the protocol of the specified `server`, either `"http"` or `"https"`.
693
684
///
694
685
/// Returns the protocol of the default server if `server` is `None`.
695
686
///
696
- /// Entries in the project configuration supersede entries in the home configuration.
697
- ///
698
687
/// If `server` is `Some` and is a complete URL,
699
688
/// including protocol and hostname,
700
689
/// returns that protocol without accessing the configuration.
@@ -703,31 +692,26 @@ impl Config {
703
692
/// Returns an `Err` if:
704
693
/// - `server` is `Some`, but not a complete URL,
705
694
/// and the supplied name does not refer to any server
706
- /// in either the project or the home configuration.
707
- /// - `server` is `None`, but neither the home nor the project configuration
708
- /// has a default server.
695
+ /// in the configuration.
696
+ /// - `server` is `None`, but the configuration does not have a default server.
709
697
pub fn protocol < ' a > ( & ' a self , server : Option < & ' a str > ) -> anyhow:: Result < & ' a str > {
710
698
if let Some ( server) = server {
711
699
if contains_protocol ( server) {
712
700
Ok ( host_or_url_to_host_and_protocol ( server) . 1 . unwrap ( ) )
713
701
} else {
714
- self . proj . protocol ( server ) . or_else ( |_| self . home . protocol ( server) )
702
+ self . home . protocol ( server)
715
703
}
716
704
} else {
717
- self . proj . default_protocol ( ) . or_else ( |_| self . home . default_protocol ( ) )
705
+ self . home . default_protocol ( )
718
706
}
719
707
}
720
708
721
709
pub fn default_identity ( & self , server : Option < & str > ) -> anyhow:: Result < & str > {
722
710
if let Some ( server) = server {
723
711
let ( host, _) = host_or_url_to_host_and_protocol ( server) ;
724
- self . proj
725
- . default_identity ( host)
726
- . or_else ( |_| self . home . default_identity ( host) )
712
+ self . home . default_identity ( host)
727
713
} else {
728
- self . proj
729
- . default_server_default_identity ( )
730
- . or_else ( |_| self . home . default_server_default_identity ( ) )
714
+ self . home . default_server_default_identity ( )
731
715
}
732
716
}
733
717
@@ -806,21 +790,6 @@ impl Config {
806
790
Ok ( toml:: from_str ( & text) ?)
807
791
}
808
792
809
- fn load_proj_config ( ) -> RawConfig {
810
- // TODO(cloutiertyler): For now we're checking for a spacetime.toml file
811
- // in the current directory. Eventually this should really be that we
812
- // search parent directories above the current directory to find
813
- // spacetime.toml files like a .gitignore file
814
- let cur_dir = std:: env:: current_dir ( ) . expect ( "No current working directory!" ) ;
815
- if let Some ( config_path) = Self :: find_config_path ( & cur_dir) {
816
- Self :: load_from_file ( & config_path)
817
- . inspect_err ( |e| eprintln ! ( "config file {config_path:?} is invalid: {e:#}" ) )
818
- . unwrap_or_default ( )
819
- } else {
820
- Default :: default ( )
821
- }
822
- }
823
-
824
793
pub fn load ( ) -> Self {
825
794
let home_path = Self :: system_config_path ( ) ;
826
795
let home = if home_path. exists ( ) {
@@ -831,17 +800,14 @@ impl Config {
831
800
RawConfig :: new_with_localhost ( )
832
801
} ;
833
802
834
- let proj = Self :: load_proj_config ( ) ;
835
-
836
- Self { home, proj }
803
+ Self { home }
837
804
}
838
805
839
806
#[ doc( hidden) ]
840
807
/// Used in tests.
841
808
pub fn new_with_localhost ( ) -> Self {
842
809
Self {
843
810
home : RawConfig :: new_with_localhost ( ) ,
844
- proj : RawConfig :: default ( ) ,
845
811
}
846
812
}
847
813
@@ -990,13 +956,9 @@ Import an existing identity with:
990
956
pub fn set_default_identity_if_unset ( & mut self , server : Option < & str > , identity : & str ) -> anyhow:: Result < ( ) > {
991
957
if let Some ( server) = server {
992
958
let ( host, _) = host_or_url_to_host_and_protocol ( server) ;
993
- self . proj
994
- . set_default_identity_if_unset ( host, identity)
995
- . or_else ( |_| self . home . set_default_identity_if_unset ( host, identity) )
959
+ self . home . set_default_identity_if_unset ( host, identity)
996
960
} else {
997
- self . proj
998
- . default_server_set_default_identity_if_unset ( identity)
999
- . or_else ( |_| self . home . default_server_set_default_identity_if_unset ( identity) )
961
+ self . home . default_server_set_default_identity_if_unset ( identity)
1000
962
}
1001
963
}
1002
964
@@ -1025,23 +987,16 @@ Update the server's fingerprint with:
1025
987
let ( host, _) = host_or_url_to_host_and_protocol ( server) ;
1026
988
Ok ( host)
1027
989
} else {
1028
- self . proj
1029
- . default_server ( )
1030
- . or_else ( |_| self . home . default_server ( ) )
1031
- . map ( ServerConfig :: nick_or_host)
990
+ self . home . default_server ( ) . map ( ServerConfig :: nick_or_host)
1032
991
}
1033
992
}
1034
993
1035
994
pub fn server_fingerprint ( & self , server : Option < & str > ) -> anyhow:: Result < Option < & str > > {
1036
995
if let Some ( server) = server {
1037
996
let ( host, _) = host_or_url_to_host_and_protocol ( server) ;
1038
- self . proj
1039
- . server_fingerprint ( host)
1040
- . or_else ( |_| self . home . server_fingerprint ( host) )
997
+ self . home . server_fingerprint ( host)
1041
998
} else {
1042
- self . proj
1043
- . default_server_fingerprint ( )
1044
- . or_else ( |_| self . home . default_server_fingerprint ( ) )
999
+ self . home . default_server_fingerprint ( )
1045
1000
}
1046
1001
}
1047
1002
0 commit comments