Closed shantanuraj closed 1 year ago
Love this proposal! Like we spoke in the call, I have no objections to it. You summarized everything correctly and we can go on about implementing it as it is.
Do you think there are better solutions regarding storing the config? Sqlite or some other markup language?
I like the idea of config being just files that the user can mess around. This allows them to add these to whatever source control they use and set them up again in a different computer. SQL databases are clumsier in this sense.
Regarding the format, I think toml has the perfect signal to noise ratio and we should stick to it!
Instead of actual regex should we just support a wildcard subset ["will/."] becomes ["will/"].
I think regex is simpler (what a sentence, eh) because we then don't need to implement our own parser and can instead rely on whatever library we use for it.
toggl: Folder tracking proposal
Progress
Goal
Introduce the ability to track arbitary folder paths.
The command would then lookup it's index of configs[^1] for given path.
On successfully parsing the config the result would be effectively the same as executing[^2]
Configuration
Schema
A standard default configuration could have these options.
With comments
Storage
Configuration can be defined either globally or on a per folder basis.
Configuration files are stored in the
$TOGGL_DIR
folder. Possible locations on different platforms are$XDG_CONFIG_HOME
/toggl-cli or$HOME
/.config/toggl-cli{FOLDERID_RoamingAppData}
/labs/toggl-cli/config$HOME
/Library/Application Support/studio.watercooler.labs.toggl-cli$TOGGL_DIR/base64(path).toml
.$TOGGL_DIR/global.toml
./Users/shantanu/dev/watercooler-labs/toggl-cli
it would be stored at$TOGGL_DIR/L1VzZXJzL3NoYW50YW51L2Rldi93YXRlcmNvb2xlci1sYWJzL3RvZ2dsLWNsaQ==.toml
.toggl .
under the path/Users/shantanu/dev/watercooler-labs/toggl-cli/src/
would use the same config.Initialization
$EDITOR
with the config path if it is set, otherwise log the config path and let the user edit it themselves.toggl config init
is invoked for a directory that's already tracked directly, log the path of existing configuration.$EDITOR
with the path or log it, depending on if$EDITOR
is configured or not.Lookup
toggl [path]
is executed it will look for stored configurations for paths upwards in the hierarchy from the current folder until it finds a tracked path./Users/shantanu/dev/watercooler-labs/toggl-cli
it would consider the followings options$TOGGL_CONFIG/L1VzZXJzL3NoYW50YW51L2Rldi93YXRlcmNvb2xlci1sYWJzL3RvZ2dsLWNsaQ==.toml
for/Users/shantanu/dev/watercooler-labs/toggl-cli
$TOGGL_CONFIG/L1VzZXJzL3NoYW50YW51L2Rldi93YXRlcmNvb2xlci1sYWJz.toml
for/Users/shantanu/dev/watercooler-labs
$TOGGL_CONFIG/L1VzZXJzL3NoYW50YW51L2Rldg==.toml
for/Users/shantanu/dev
$TOGGL_CONFIG/L1VzZXJzL3NoYW50YW51.toml
for/Users/shantanu
$TOGGL_CONFIG/L1VzZXJz.toml
for/Users
$TOGGL_CONFIG/Lw==.toml
for/
Parsing
The config is parsed and must return a valid options struct for the
toggl start
command.The first step is to choose the correct block.
['*']
in a separate variabledefault_config
, all other block names are stored in theconfigs
array.default_config
.configs
regular expression to find a block that ourbranch
satisfies.Then we process the
config
, by substituting themarcros
with their resolved values.{{branch}}
, if this macro is used we must ensure it is supported by the current path else fail and inform the user the current path is not under version control.{{$ shell_expression }}
({{$shell_expression}}
without spaces is the same.)If either of the fields
workspace
,project
,task
are configured, we must query the API to get the corresponding IDs (workspace_id
,project_id
,task_id
).project
andtask
fields if the API returns an error, we must not fail the command and create the relevant entity with that name.workspace
if the API returns an error, we must fail the command and inform the user that the workspace is missing.In the end we return a struct that can be interpreted by the
toggl start
command.Supported macros
{{branch}}
{{base_dir}}
toggl config init
{{current_dir}}
{{parent_base_dir}}
{{base_dir}}
{{parent_dir}}
{{current_dir}}
{{git_root}}
{{base_dir}}
{{parent_git_root}}
{{parent_dir}}
{{$[shell_expression]}}
shell_expression
and uses its resultSample scenarios
Inbuilt macros only
Tracked Directory
/Users/shantanu/dev/watercooler-labs/toggl-cli
Branch
add-folder-tracking
API State
Configuration
Output
With Custom macros
Tracked Directory
/Users/shantanu/dev/watercooler-labs/UnityGame
Current directory
/Users/shantanu/dev/watercooler-labs/UnityGame/android
Branch
Not tracked under source control
API State
Configuration
Output
Questions
['will/.*"]
becomes["will/*']
.[^1]: See config proposal. [^2]: At the time of writing this issue, we do not support configuring workspace, project, task or tags, this is a prequisite for supporting all features of the proposed configuration schema.