-
-
Notifications
You must be signed in to change notification settings - Fork 18
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
Refactor commands into separate modules #94
Conversation
pub fn fmt_tool_names<F: FnMut(&String) -> String>(fmt_tool: F) -> String { | ||
build_db() | ||
.keys() | ||
.map(fmt_tool) | ||
.collect::<Vec<String>>() | ||
.join("\n") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to keep the previous implementation with writeln!
but wasn't able to specify the proper function type signature so I went for a simpler implementation. It is probably less efficient but it looks pretty simple and the performance overhead is not noticeable actually. It still works instantaneously.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh right join
actually makes sense here. I was looking for a way to concatenate strings like in python, turns out it is the same...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a bit sad it doesn't work with iterators and I need to collect
first. There's itertools
which implements this. But I didn't want to add an extra crate for a minor convenience.
Moreover, according to this comment, join
on Vec
is even faster than from itertools
because it can allocate the required amount of memory.
The comment is 5 years old so things could've changed since then
src/config/template.rs
Outdated
# Without this tag latest will be used | ||
# tag = "13.0.0" | ||
|
||
# Asset name to download on linux OSes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did not realize these options were not global in the config. I guess it does make sense since not all tools will support musl or libc or windows.
Maybe this is just me but I like having the line start with the # This configuration is automatically generated by tool-sync 0.1.0
# https://github.com/chshersh/tool-sync
#######################################
#
# Installation directory for all the tools:
# store_directory = "$HOME/.local/bin"
#
# tool-sync provides native support for some of the tools without the need to
# configure them. Uncomment all the tools you want to install with a single
# 'tool sync' command:
#
# [bat]
# [difftastic]
# [exa]
# [fd]
# [ripgrep]
# [tool-sync]
#
# You can configure the installation of any tool by specifying corresponding options:
#
# [ripgrep] # Name of the tool (new or one of the hardcoded to override default settings)
# owner = "BurntSushi" # GitHub repository owner
# repo = "ripgrep" # GitHub repository name
# exe_name = "rg" # Executable name inside the asset
# 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" |
### START ### | ||
|
||
# ensure this directory is listed in $PATH | ||
store_directory = "/path/to/install/directory" | ||
|
||
[bat] | ||
[exa] | ||
[fd] | ||
[ripgrep] | ||
|
||
[bat] | ||
[exa] | ||
[fd] | ||
[ripgrep] | ||
### END ### |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good change actually, this makes it more clear where the config starts and ends.
pub fn fmt_tool_names<F: FnMut(&String) -> String>(fmt_tool: F) -> String { | ||
build_db() | ||
.keys() | ||
.map(fmt_tool) | ||
.collect::<Vec<String>>() | ||
.join("\n") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh right join
actually makes sense here. I was looking for a way to concatenate strings like in python, turns out it is the same...
I don't might changing the format actually. I don't have strong feelings about one or another. Having all the comments as leading comments makes it look more consistent 👍🏻 |
Some refactoring to change a few things:
match
inlib.rs
concisedefault-config
sync
orinstall
command