Skip to content

Commit 336056e

Browse files
authored
CLI - Remove project-specific config files (#1665)
Co-authored-by: Zeke Foppa <bfops@users.noreply.github.com>
1 parent eeaa00a commit 336056e

File tree

1 file changed

+20
-65
lines changed

1 file changed

+20
-65
lines changed

crates/cli/src/config.rs

Lines changed: 20 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ pub struct RawConfig {
108108

109109
#[derive(Debug, Clone)]
110110
pub struct Config {
111-
proj: RawConfig,
112111
home: RawConfig,
113112
}
114113

@@ -583,10 +582,7 @@ Fetch the server's fingerprint with:
583582

584583
impl Config {
585584
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()
590586
}
591587

592588
/// Add a `ServerConfig` to the home configuration.
@@ -645,18 +641,15 @@ impl Config {
645641
///
646642
/// Returns the URL of the default server if `server` is `None`.
647643
///
648-
/// Entries in the project configuration supersede entries in the home configuration.
649-
///
650644
/// If `server` is `Some` and is a complete URL,
651645
/// including protocol and hostname,
652646
/// returns that URL without accessing the configuration.
653647
///
654648
/// Returns an `Err` if:
655649
/// - `server` is `Some`, but not a complete URL,
656650
/// 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.
660653
pub fn get_host_url(&self, server: Option<&str>) -> anyhow::Result<String> {
661654
Ok(format!("{}://{}", self.protocol(server)?, self.host(server)?))
662655
}
@@ -665,36 +658,32 @@ impl Config {
665658
///
666659
/// Returns the hostname of the default server if `server` is `None`.
667660
///
668-
/// Entries in the project configuration supersede entries in the home configuration.
669-
///
670661
/// If `server` is `Some` and is a complete URL,
671662
/// including protocol and hostname,
672663
/// returns that hostname without accessing the configuration.
673664
///
674665
/// Returns an `Err` if:
675666
/// - `server` is `Some`, but not a complete URL,
676667
/// 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.
680671
pub fn host<'a>(&'a self, server: Option<&'a str>) -> anyhow::Result<&'a str> {
681672
if let Some(server) = server {
682673
if contains_protocol(server) {
683674
Ok(host_or_url_to_host_and_protocol(server).0)
684675
} else {
685-
self.proj.host(server).or_else(|_| self.home.host(server))
676+
self.home.host(server)
686677
}
687678
} else {
688-
self.proj.default_host().or_else(|_| self.home.default_host())
679+
self.home.default_host()
689680
}
690681
}
691682

692683
/// Get the protocol of the specified `server`, either `"http"` or `"https"`.
693684
///
694685
/// Returns the protocol of the default server if `server` is `None`.
695686
///
696-
/// Entries in the project configuration supersede entries in the home configuration.
697-
///
698687
/// If `server` is `Some` and is a complete URL,
699688
/// including protocol and hostname,
700689
/// returns that protocol without accessing the configuration.
@@ -703,31 +692,26 @@ impl Config {
703692
/// Returns an `Err` if:
704693
/// - `server` is `Some`, but not a complete URL,
705694
/// 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.
709697
pub fn protocol<'a>(&'a self, server: Option<&'a str>) -> anyhow::Result<&'a str> {
710698
if let Some(server) = server {
711699
if contains_protocol(server) {
712700
Ok(host_or_url_to_host_and_protocol(server).1.unwrap())
713701
} else {
714-
self.proj.protocol(server).or_else(|_| self.home.protocol(server))
702+
self.home.protocol(server)
715703
}
716704
} else {
717-
self.proj.default_protocol().or_else(|_| self.home.default_protocol())
705+
self.home.default_protocol()
718706
}
719707
}
720708

721709
pub fn default_identity(&self, server: Option<&str>) -> anyhow::Result<&str> {
722710
if let Some(server) = server {
723711
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)
727713
} 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()
731715
}
732716
}
733717

@@ -806,21 +790,6 @@ impl Config {
806790
Ok(toml::from_str(&text)?)
807791
}
808792

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-
824793
pub fn load() -> Self {
825794
let home_path = Self::system_config_path();
826795
let home = if home_path.exists() {
@@ -831,17 +800,14 @@ impl Config {
831800
RawConfig::new_with_localhost()
832801
};
833802

834-
let proj = Self::load_proj_config();
835-
836-
Self { home, proj }
803+
Self { home }
837804
}
838805

839806
#[doc(hidden)]
840807
/// Used in tests.
841808
pub fn new_with_localhost() -> Self {
842809
Self {
843810
home: RawConfig::new_with_localhost(),
844-
proj: RawConfig::default(),
845811
}
846812
}
847813

@@ -990,13 +956,9 @@ Import an existing identity with:
990956
pub fn set_default_identity_if_unset(&mut self, server: Option<&str>, identity: &str) -> anyhow::Result<()> {
991957
if let Some(server) = server {
992958
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)
996960
} 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)
1000962
}
1001963
}
1002964

@@ -1025,23 +987,16 @@ Update the server's fingerprint with:
1025987
let (host, _) = host_or_url_to_host_and_protocol(server);
1026988
Ok(host)
1027989
} 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)
1032991
}
1033992
}
1034993

1035994
pub fn server_fingerprint(&self, server: Option<&str>) -> anyhow::Result<Option<&str>> {
1036995
if let Some(server) = server {
1037996
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)
1041998
} else {
1042-
self.proj
1043-
.default_server_fingerprint()
1044-
.or_else(|_| self.home.default_server_fingerprint())
999+
self.home.default_server_fingerprint()
10451000
}
10461001
}
10471002

0 commit comments

Comments
 (0)