chshersh / tool-sync

🧰 Download pre-built binaries of all your favourite tools with a single command
https://crates.io/crates/tool-sync
Mozilla Public License 2.0
69 stars 16 forks source link

Implement the 'Partial Options Monoid' pattern for the configuration #130

Open chshersh opened 1 year ago

chshersh commented 1 year ago

This pattern is common in the FP world. The description (in Haskell) can be found here:

The idea is the following:

That's all! With this approach, it should be possible to configure different options from different sources and have a uniform config.

crudiedo commented 1 year ago

Hi everyone,

I wanted to make sure we have the same variables name format in mind:

Currently, we have 2 different kinds of things we could configure - it's either store_directory\proxy (non tools related) or any tools field.

For non-tools related variables it's quite simple:

# ENV
TOOL_SYNC_STORE_DIRECTORY=~/.bin
# Cli
--store_directory=~/.bin

And for the tools it would be like:

# ENV
TOOL_SYNC_BOTTOM_OWNER=clementtsang
TOOL_SYNC_BOTTOM_REPO=bottom
TOOL_SYNC_BOTTOM_EXE_NAME=btm
TOOL_SYNC_ASSET_NAME_MACOS=darwin
# Cli
--bottom.owner=clementtsang
--bottom.repo=bottom
--bottom.exe_name=btm
--bottom.asset_name.macos=darwin
  1. Do we want to use TOOL_SYNC as the env prefix? I thought about just TOOL, but it's quite ambiguous and could be reused by any other tool (:

  2. Do we really want to let the ENV configure tools? It looks like parsing that would be a mess (still need to do it for the cli though), and even with some generic parsing function the code will become more complicated.

chshersh commented 1 year ago

@crudiedo Thanks for moving the conversation! Answering your question:

Do we want to use TOOL_SYNC as the env prefix? I thought about just TOOL, but it's quite ambiguous and could be reused by any other tool (:

I agree about the TOOL_SYNC_ prefix for environment variables 👍🏻

Do we really want to let the ENV configure tools? It looks like parsing that would be a mess (still need to do it for the cli though), and even with some generic parsing function the code will become more complicated.

No, we don't environment variables for individual tools 🙂 The usage for environment variables is to apply some configuration for every tool invocation and usually this is some global setting. Tool details are too granular and individual to be supported by env variables (and indeed will be a mess to parse as you mentioned).

My opinion:

Env:

CLI args:

File: