Skip to content

Commit

Permalink
feat: configuration in toolbx.yaml
Browse files Browse the repository at this point in the history
I renamed config.yaml to toolbx.yaml and now it's also loaded from home
directory ~/.toolbx.yaml. This will help with initialization of new
toolbx installation
  • Loading branch information
Zdenko Vrabel committed May 10, 2022
1 parent ae6d6e3 commit f8e66b9
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,12 @@ any place.
But for easy to use you should move the `toolbx` binary somewhere in your `PATH`
(e.g. to `/usr/local/bin`).

## Quick Start

When you installed `toolbx` binary, as second step is configuration of your
command repository. It's repository where are all commands and subcommands
defined. You can use `toolbx-demo` repository.

```
echo "repository: https://github.com/sn3d/toolbx-demo.git" > ~/.toolbx.yaml
```
8 changes: 8 additions & 0 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,12 @@ var (
// NoMetadataError indicates the command.yaml is missing in the subcommand
// folder
NoMetadataError = errors.New("no metadata file")

// MissingRepoError indicates you have probably not configured toolbx. You should
// create configuration file and define Git repository where are commands
// defined:
//
// echo "repository: https://github.com/sn3d/toolbx-demo.git" > ~/.toolbx.yaml
//
MissingRepoError = errors.New("no repository with commands defined")
)
8 changes: 7 additions & 1 deletion options.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,17 @@ func defaultValues(instance *Toolbx) {

func WithToolbxPath(toolbxpath string) ToolbxOption {
toolbxpath = toolbxPath(toolbxpath)
homeDir, _ := os.UserHomeDir()
return func(instance *Toolbx) {
instance.syncFile = filepath.Join(toolbxpath, "sync")
WithInstallationsDir(filepath.Join(toolbxpath, "installed"))(instance)
WithCommandsDir(filepath.Join(toolbxpath, "commands"))(instance)
WithConfigFile(filepath.Join(toolbxpath, "config.yaml"))(instance)

// The configuration is loaded in following order:
// - ~/.toolbx.yaml
// - $TOOLBX/toolbx.yaml
WithConfigFile(filepath.Join(homeDir, ".toolbx.yaml"))(instance)
WithConfigFile(filepath.Join(toolbxpath, "toolbx.yaml"))(instance)
}
}

Expand Down
4 changes: 4 additions & 0 deletions toolbx.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ func Create(options ...ToolbxOption) (*Toolbx, error) {
}

// validation & post-initialization
if toolbx.syncRepo == "" {
return nil, MissingRepoError
}

toolbx.installers = map[string]install.Installer{
"https+zip": archive.Installer(toolbx.gitlabToken),
}
Expand Down

0 comments on commit f8e66b9

Please sign in to comment.