Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add config path for windows OS #75

Merged
merged 11 commits into from
Mar 3, 2022
32 changes: 24 additions & 8 deletions cli/src/modules/configuration.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::env;
morrieinmaas marked this conversation as resolved.
Show resolved Hide resolved
use std::path::Path;
use std::{fs, fmt};
use std::{fmt, fs};

use clap::Args;

Expand All @@ -24,15 +25,31 @@ struct ConfigurationEnvironment {

impl fmt::Display for ConfigurationEnvironment {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "[{}]\nendpoint={}{}", self.environment, self.endpoint, self.api_key.as_ref().map(|val| format!("\napi_key={val}")).unwrap_or_else(|| "".to_string()))
write!(
f,
"[{}]\nendpoint={}{}",
self.environment,
self.endpoint,
self.api_key
.as_ref()
.map(|val| format!("\napi_key={val}"))
.unwrap_or_else(|| "".to_string())
)
}
}


// TODO: we should implement `from` so we can use todo and have a cleaner api
pub async fn parse_configuration_args(options: &ConfigurationOptions, logger: Log) -> Result<()> {
let home = env!("HOME");
let default_config_path = Path::new(home).join(".config/aries-cli/config.ini");
let default_config_path;
if cfg!(windows) {
let home = "C:\\Program Files\\Common Files\\".to_string();
morrieinmaas marked this conversation as resolved.
Show resolved Hide resolved
let default_config_path_win = Path::new(&home).join(".config\\aries-cli\\config.ini");
morrieinmaas marked this conversation as resolved.
Show resolved Hide resolved
default_config_path = default_config_path_win
} else {
morrieinmaas marked this conversation as resolved.
Show resolved Hide resolved
let home = env!("HOME");
let default_config_path_unix = Path::new(home).join(".config/aries-cli/config.ini");
default_config_path = default_config_path_unix
}
if options.initialise {
initialise(&default_config_path)?;
logger.log("Initialised the configuration!");
Expand All @@ -50,11 +67,10 @@ fn view(path: &Path, logger: Log) -> Result<()> {
let output = fs::read_to_string(path)?;
logger.log(output);
Ok(())

}

fn initialise(path: &Path) -> Result<()> {
let config = ConfigurationEnvironment{
let config = ConfigurationEnvironment {
environment: "Default".to_string(),
endpoint: "https://agent.community.animo.id".to_string(),
api_key: None,
Expand All @@ -72,7 +88,7 @@ fn initialise(path: &Path) -> Result<()> {

// Create the configuration file
fs::File::create(&path)?;

// Write the default configuration to the file
fs::write(path, config.to_string())?;

Expand Down