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

[#52] Adds a generate command for a default .tools.toml file #62

Merged
merged 11 commits into from
Sep 8, 2022
Merged
Show file tree
Hide file tree
Changes from 10 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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,16 @@ the following command (Unix-only):
```shell
curl https://raw.githubusercontent.com/chshersh/tool-sync/main/example-tool-sync-config.toml > ~/.tool.toml
```
A default config can be also be generated by running `tool --config=path/to/config generate`.
This will generate an example file at `path/to/config`.
MitchellBerend marked this conversation as resolved.
Show resolved Hide resolved

The above example config lists some tools natively supported by `tool-sync` and
therefore they don't require extra configuration.

To specify a tool not supported by `tool-sync`, add a TOML table entry and list
all the required fields like in the example below:


```toml
[tokei]
owner = "XAMPPRocky" # GitHub username
Expand Down
1 change: 1 addition & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod cli;
pub mod schema;
pub mod template;
pub mod toml;
3 changes: 3 additions & 0 deletions src/config/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@ pub struct Cli {
pub enum Command {
/// Sync all tools specified in configuration file
Sync,

/// Generate a default .tools.toml file and prints it to std out
DefaultConfig,
}
38 changes: 38 additions & 0 deletions src/config/template.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/// This file only holds the template that is used to generate a default .tools.toml.

pub const CONFIG_TEMPLATE: &str = r##"# # tool-sync default configuration file
# https://github.com/chshersh/tool-sync
# This file was automatically generated by tool-sync
#####################################################
#
#
# store_directory = "$HOME/.local/bin"
#
# tool-sync provides native support for some of the tools without the need to configure them
# Uncomment the tools you want to have them
#
# [bat]
# [difftastic]
# [fd]
# [ripgrep]
#
# To add configuration for other tools these are the config options:
# [ripgrep]
# owner = "BurntSushi"
# repo = "ripgrep"
# exe_name = "rg"
#
# # Uncomment to download a specific version or tag.
# # Without this tag latest will be used
# # tag = "13.0.0"
#
#
# Asset name to download on linux OSes
# asset_name.linux = "x86_64-unknown-linux-musl"
#
# uncomment if you want to install on macOS as well
# asset_name.macos = "apple-darwin"
#
# uncomment if you want to install on Windows as well
# asset_name.windows = "x86_64-pc-windows-msvc"
"##;
30 changes: 19 additions & 11 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,30 @@ use clap::Parser;
use std::path::PathBuf;

use crate::config::cli::{Cli, Command};
use crate::config::template;
use crate::config::toml;
use crate::sync::sync;

const DEFAULT_CONFIG_PATH: &str = ".tool.toml";

pub fn run() {
let cli = Cli::parse();
let config_path = resolve_config_path(cli.config);
let config_path = resolve_config_path(cli.config.clone());

match toml::parse_file(&config_path) {
Err(e) => {
err::abort_with(&format!(
"Error parsing configuration at path {}: {}",
config_path.display(),
e.display()
));
}
Ok(tool) => match cli.command {
Command::Sync => sync(tool),
match cli.command {
Command::Sync => match toml::parse_file(&config_path) {
Err(e) => {
err::abort_with(&format!(
"Error parsing configuration at path {}: {}",
config_path.display(),
e.display()
));
}
Ok(tool) => {
sync(tool);
}
},
Command::DefaultConfig => generate_config(),
}
}

Expand All @@ -46,3 +50,7 @@ fn resolve_config_path(config_path: Option<PathBuf>) -> PathBuf {
},
}
}

fn generate_config() {
println!("{}", template::CONFIG_TEMPLATE);
}