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

Move config file to standard location #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# 0.2.0

Changed location of config file

now following the OS standard

// Linux: /home/alice/.config/pndev/pndev.toml
// macOS: /Users/Alice/Library/Preferences/rs.pndev.pndev/pndev.toml
typeoneerror marked this conversation as resolved.
Show resolved Hide resolved

2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pndev"
version = "0.1.21"
version = "0.2.0"
authors = ["Mattia Gheda <ghedamat@gmail.com>"]
edition = "2018"

Expand Down
16 changes: 13 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,28 @@ from the [releases](https://github.com/PrecisionNutrition/pndev/releases) page.

## Configure

If you would like to customize the installation path for the repositories you can create a
`.pndev_config.toml` file in your home directory;
To customize the cloning path for the PN repositories you edit or create modify the `pndev` config file.

The location of this file depends on your operating system.

// Linux: /home/alice/.config/pndev/pndev.toml
// macOS: /Users/Alice/Library/Preferences/rs.pndev.pndev/pndev.toml

if this is your first time using `pndev` you can run `pndev doctor` and the config file will be generated

```
# run
pndev doctor
# this will create a ~/.pndev_config.toml for you to edit if you don't have one

# edit the generated config file
# Linux: /home/alice/.config/pndev/pndev.toml
# macOS: /Users/Alice/Library/Preferences/rs.pndev.pndev/pndev.toml
```

### Config file format

```
# install path is relative to your home directory, do not use trailing slashes
install_path = 'DEV/PN'
```

Expand Down
9 changes: 5 additions & 4 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ impl ::std::default::Default for Config {
}
}

const CONFIG_FILE_NAME: &str = ".pndev_config";
// Linux: /home/alice/.config/pndev/pndev.toml
// macOS: /Users/Alice/Library/Preferences/rs.pndev.pndev/pndev.toml
const CONFIG_FILE_NAME: &str = "pndev";

impl Config {
pub fn new() -> Self {
let path = format!("{}/{}", Self::home_path_str(), CONFIG_FILE_NAME);
info!("Loading config from {}.toml", path);
let cfg: Config = confy::load(&path).expect("Config load/write failed");
info!("Loading/generating config file");
let cfg: Config = confy::load(CONFIG_FILE_NAME).expect("Config load/write failed");
cfg
}

Expand Down
2 changes: 2 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ fn main() -> Result<(), ExitFailure> {
warn!("LogLevel Warn");
info!("LogLevel Info");

config::Config::new();

let command_result = match args.command {
CliCommand::Prepare => Command::prepare(),
CliCommand::Shell => Command::shell(),
Expand Down