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

[#73] Adds build.rs to generate a default config template with tool version #78

Merged
merged 27 commits into from
Sep 15, 2022
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
e4a281f
adding cargo fmted files
MitchellBerend Sep 10, 2022
56910b3
Added comment back that was deleted accidentally
MitchellBerend Sep 10, 2022
460d021
fixed formatting
MitchellBerend Sep 10, 2022
3e5d4f7
fixed more formatting issues
MitchellBerend Sep 10, 2022
f7f5c57
fixed yet more formatting issues
MitchellBerend Sep 10, 2022
243eb56
fixed variable name
MitchellBerend Sep 10, 2022
551706b
changed back template and incorporated a version
MitchellBerend Sep 10, 2022
d5196ac
converted match statement to a hashmap
MitchellBerend Sep 10, 2022
ea0bd50
fixed unwrapping issue
MitchellBerend Sep 10, 2022
4c11c31
Merge branch 'main' into 73-add-version-to-config
MitchellBerend Sep 10, 2022
3881ae7
made the template a string literal so there is no need for escaping "…
MitchellBerend Sep 11, 2022
4ffaae6
added default-config output test
MitchellBerend Sep 11, 2022
6e31ff8
This commit should fail in ci
MitchellBerend Sep 11, 2022
4b2320e
corrected typo in test name and added more output when test fails
MitchellBerend Sep 11, 2022
10a5b70
removed error to make ci pass again
MitchellBerend Sep 11, 2022
62fef0e
added more tests to increase code coverage
MitchellBerend Sep 11, 2022
ae60e3b
Merge branch 'main' into 73-add-version-to-config
MitchellBerend Sep 13, 2022
8b12850
added a generated tools block so the default config that is generated…
MitchellBerend Sep 13, 2022
093e667
converted simple panic to panic_suggest_issue from src/err.rs
MitchellBerend Sep 13, 2022
eaf6924
changed test only test the function itself instead of only the error
MitchellBerend Sep 14, 2022
2870cb4
added more clarity on a test when its function succeeds when it shoul…
MitchellBerend Sep 14, 2022
c418edc
removed test that is already covered in characterization test
MitchellBerend Sep 14, 2022
0d7e91a
removed Option<ToolInfo> from the btree value type
MitchellBerend Sep 14, 2022
03cd372
changed output of default-config command test
MitchellBerend Sep 14, 2022
6e1d5ed
wrapped parse_file in a catch unwind so the test actually checks if t…
MitchellBerend Sep 14, 2022
07c9d0e
Fixed typo
MitchellBerend Sep 14, 2022
9056e81
fixed actual typo instead of removing it
MitchellBerend Sep 14, 2022
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
26 changes: 16 additions & 10 deletions src/config/template.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
/// 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
pub fn config_template() -> String {
format!(
"# This config file was generated for version {version}
#
# # tool-sync default configuration file
# https://github.com/chshersh/tool-sync
# This file was automatically generated by tool-sync
#####################################################
#
#
# store_directory = "$HOME/.local/bin"
# store_directory = \"$HOME/.local/bin\"
MitchellBerend marked this conversation as resolved.
Show resolved Hide resolved
#
# tool-sync provides native support for some of the tools without the need to configure them
# Uncomment the tools you want to have them
Expand All @@ -18,21 +22,23 @@ pub const CONFIG_TEMPLATE: &str = r##"# # tool-sync default configuration file
#
# To add configuration for other tools these are the config options:
# [ripgrep]
# owner = "BurntSushi"
# repo = "ripgrep"
# exe_name = "rg"
# 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"
# # tag = \"13.0.0\"
#
#
# Asset name to download on linux OSes
# asset_name.linux = "x86_64-unknown-linux-musl"
# asset_name.linux = \"x86_64-unknown-linux-musl\"
#
# uncomment if you want to install on macOS as well
# asset_name.macos = "apple-darwin"
# asset_name.macos = \"apple-darwin\"
#
# uncomment if you want to install on Windows as well
# asset_name.windows = "x86_64-pc-windows-msvc"
"##;
# asset_name.windows = \"x86_64-pc-windows-msvc\"",
version = env!("CARGO_PKG_VERSION")
)
}
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,5 @@ fn resolve_config_path(config_path: Option<PathBuf>) -> PathBuf {
}

fn generate_config() {
println!("{}", template::CONFIG_TEMPLATE);
println!("{}", template::config_template());
}
69 changes: 49 additions & 20 deletions src/sync/db.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
use std::collections::BTreeMap;

use crate::model::asset_name::AssetName;
use crate::model::tool::{ToolInfo, ToolInfoTag};

/// Get info about known tools from a hardcoded database
pub fn lookup_tool(tool_name: &str) -> Option<ToolInfo> {
match tool_name {
"bat" => Some(ToolInfo {
let mut known_db = build_db();
MitchellBerend marked this conversation as resolved.
Show resolved Hide resolved
match known_db.get_mut(tool_name) {
Some(tool_info) => tool_info.take(),
None => None,
}
}

fn build_db() -> BTreeMap<String, Option<ToolInfo>> {
let mut tools: BTreeMap<String, Option<ToolInfo>> = BTreeMap::new();

tools.insert(
"bat".into(),
Some(ToolInfo {
owner: "sharkdp".to_string(),
repo: "bat".to_string(),
exe_name: "bat".to_string(),
Expand All @@ -15,7 +28,10 @@ pub fn lookup_tool(tool_name: &str) -> Option<ToolInfo> {
},
tag: ToolInfoTag::Latest,
}),
"difftastic" => Some(ToolInfo {
);
tools.insert(
"difftastic".into(),
Some(ToolInfo {
owner: "Wilfred".to_string(),
repo: "difftastic".to_string(),
exe_name: "difft".to_string(),
Expand All @@ -26,7 +42,10 @@ pub fn lookup_tool(tool_name: &str) -> Option<ToolInfo> {
},
tag: ToolInfoTag::Latest,
}),
"exa" => Some(ToolInfo {
);
tools.insert(
"exa".into(),
Some(ToolInfo {
owner: "ogham".to_string(),
repo: "exa".to_string(),
exe_name: "exa".to_string(),
Expand All @@ -37,7 +56,10 @@ pub fn lookup_tool(tool_name: &str) -> Option<ToolInfo> {
},
tag: ToolInfoTag::Latest,
}),
"fd" => Some(ToolInfo {
);
tools.insert(
"fd".into(),
Some(ToolInfo {
owner: "sharkdp".to_string(),
repo: "fd".to_string(),
exe_name: "fd".to_string(),
Expand All @@ -48,7 +70,10 @@ pub fn lookup_tool(tool_name: &str) -> Option<ToolInfo> {
},
tag: ToolInfoTag::Latest,
}),
"ripgrep" => Some(ToolInfo {
);
tools.insert(
"ripgrep".into(),
Some(ToolInfo {
owner: "BurntSushi".to_string(),
repo: "ripgrep".to_string(),
exe_name: "rg".to_string(),
Expand All @@ -59,7 +84,10 @@ pub fn lookup_tool(tool_name: &str) -> Option<ToolInfo> {
},
tag: ToolInfoTag::Latest,
}),
"tool-sync" => Some(ToolInfo {
);
tools.insert(
"tool-sync".into(),
Some(ToolInfo {
owner: "chshersh".to_string(),
repo: "tool-sync".to_string(),
exe_name: "tool".to_string(),
Expand All @@ -70,17 +98,18 @@ pub fn lookup_tool(tool_name: &str) -> Option<ToolInfo> {
},
tag: ToolInfoTag::Latest,
}),
// "tokei" => Some(ToolInfo {
// owner: "XAMPPRocky".to_string(),
// repo: "tokei".to_string(),
// exe_name: "tokei".to_string(),
// asset_name: AssetName {
// linux: Some("x86_64-unknown-linux-musl".to_string()),
// macos: Some("apple-darwin".to_string()),
// windows: Some("x86_64-pc-windows-msvc".to_string()),
// }
// tag: ToolInfoTag::Latest,
// }),
_ => None,
}
);
// tools.insert("tokei", Some(ToolInfo {
// owner: "XAMPPRocky".to_string(),
// repo: "tokei".to_string(),
// exe_name: "tokei".to_string(),
// asset_name: AssetName {
// linux: Some("x86_64-unknown-linux-musl".to_string()),
// macos: Some("apple-darwin".to_string()),
// windows: Some("x86_64-pc-windows-msvc".to_string()),
// }
// tag: ToolInfoTag::Latest,
// }));
//
tools
}