Skip to content

Commit

Permalink
Enable downloading recipe from official repository (#28)
Browse files Browse the repository at this point in the history
* Enable downloading recipe from official repository

* Use flags in rollback and install commands

* Allow JSON recipes

* Test loading recipe from URL

* Polish tests
  • Loading branch information
pkosiec authored May 13, 2019
1 parent 426df80 commit e2f38f2
Show file tree
Hide file tree
Showing 30 changed files with 782 additions and 336 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ go:
- 1.11.x

before_install:
- DEP_RELEASE_TAG='v0.4.1' curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
- DEP_RELEASE_TAG='v0.5.0' curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh

install:
- dep ensure -v -vendor-only
Expand Down
55 changes: 33 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ Terminer is an cross-platform installer for terminal presets. Install Fish or ZS
- [Usage](#usage)
- [Quick start](#quick-start)
- [Recipe](#recipe)
- [Recipes](#recipes)
- [Available commands](#available-commands)
- [`install`](#install)
- [`rollback`](#rollback)
Expand Down Expand Up @@ -50,21 +49,23 @@ The most basic commands are `install` and `rollback`.

### Quick start

To install a recipe, run:
To install a recipe from official repository, run:

```bash
terminer install [file path or URL]
terminer install [recipe name]
```

To rollback a recipe, run:
To rollback a recipe from official repository, run:

```bash
terminer rollback [file path or URL]
terminer rollback [recipe name]
```

To see all official recipes, navigate to the [`recipes`](./recipes) directory.

### Recipe

Recipe is a YAML file with shell commands put in a proper order. Recipe consists of stages, which contain steps. Every step is a different shell command.
Recipe is a YAML or JSON file with shell commands put in a proper order. Recipe consists of stages, which contain steps. Every step is a different shell command.

This is an example recipe, which just prints messages for all steps in all stages - not only during install, but also for rollback operation:

Expand Down Expand Up @@ -109,50 +110,60 @@ stages:
run: echo "Rollback of Step 1 of Stage 2"
```
## Recipes
To see all official recipes, navigate to the [`recipes`](./recipes) directory.

## Available commands
The following section describes all available commands in Terminer CLI.
### `install`

Install command installs a recipe from a local or remote file. Provide a relative or absolute path to a YAML file with recipe or an URL to download it.
Install command installs a recipe from the official recipe repository. You can use additional flags to install a recipe from a local or remote file.

**Usage**

```bash
terminer install [file path or URL]
terminer install [recipe name]
```

**Flags**

-f, --filepath string Recipe file path
-h, --help help for install
-u, --url string Recipe URL

**Examples**

```
terminer install ./recipe.yaml`
terminer install /Users/$USER/recipe.yaml`
terminer install https://example.com/recipe.yaml`
terminer install zsh-starter
terminer install -f ./recipe.yaml
terminer install --file /Users/sample-user/recipe.yml
terminer install -u https://example.com/recipe.yaml
terminer install --url http://foo.bar/recipe.yml
```
### `rollback`
Rollback command rollbacks a recipe from a local or remote file.
Provide a relative or absolute path to a YAML file with recipe
or an URL to download it.
Rollback command uninstalls a recipe from the official recipe repository. You can use additional flags to rollback a recipe from a local or remote file.
**Usage**
```bash
terminer rollback [file path or URL]
terminer rollback [recipe name]
```

**Flags**

-f, --filepath string Recipe file path
-h, --help help for install
-u, --url string Recipe URL

**Examples**

```bash
terminer rollback ./recipe.yaml
terminer rollback /Users/sample-user/recipe.yaml
terminer rollback https://example.com/recipe.yaml
terminer rollback zsh-starter
terminer rollback -f ./recipe.yaml
terminer rollback --file /Users/sample-user/recipe.yml
terminer rollback -u https://example.com/recipe.yaml
terminer rollback --url http://foo.bar/recipe.yml
```

### `version`
Expand Down
38 changes: 14 additions & 24 deletions cmd/install.go
Original file line number Diff line number Diff line change
@@ -1,40 +1,30 @@
package cmd

import (
"github.com/pkosiec/terminer/internal/printer"
"github.com/pkosiec/terminer/internal/recipecmd"
"github.com/spf13/cobra"
)

// installCmd represents the install command
var installCmd = &cobra.Command{
Use: "install [file path or URL]",
Short: "Installs a recipe from given path or URL",
Long: `Install command installs a recipe from a local or remote file.
Provide a relative or absolute path to a YAML file with recipe
or an URL to download it.
Use: "install [recipe name]",
Short: "Installs a recipe from official repository, given path or URL",
Long: `Install command installs a recipe from the official recipe repository.
You can use additional flags to install a recipe from a local or remote file.
Examples:
terminer install ./recipe.yaml
terminer install /Users/sample-user/recipe.yaml
terminer install https://example.com/recipe.yaml
terminer install zsh-starter
terminer install -f ./recipe.yaml
terminer install --file /Users/sample-user/recipe.yml
terminer install -u https://example.com/recipe.yaml
terminer install --url http://foo.bar/recipe.yml
`,
Args: validateInstallRollbackArgs,
RunE: runInstall,
Args: recipecmd.ValidateArgs,
RunE: recipecmd.Run(recipecmd.Install),
DisableFlagsInUseLine: true,
}

func init() {
recipecmd.SupportFlags(installCmd)
rootCmd.AddCommand(installCmd)
}

func runInstall(cmd *cobra.Command, args []string) error {
p := printer.New()
i, err := setupInstaller(args[0], p)
if err != nil {
return err
}

err = i.Install()
p.Result(err)

return nil
}
70 changes: 0 additions & 70 deletions cmd/install_test.go

This file was deleted.

37 changes: 14 additions & 23 deletions cmd/rollback.go
Original file line number Diff line number Diff line change
@@ -1,40 +1,31 @@
package cmd

import (
"github.com/pkosiec/terminer/internal/printer"
"github.com/pkosiec/terminer/internal/recipecmd"
"github.com/spf13/cobra"
)

// rollbackCmd represents the rollback command
var rollbackCmd = &cobra.Command{
Use: "rollback [file path or URL]",
Short: "Rollbacks a recipe from given path or URL",
Long: `Rollback command rollbacks a recipe from a local or remote file.
Provide a relative or absolute path to a YAML file with recipe
or an URL to download it.
Use: "rollback [recipe name]",
Short: "Rollbacks a recipe from official repository, given path or URL",
Long: `Rollback command uninstalls a recipe from the official recipe repository.
You can use additional flags to rollback a recipe from a local or remote file.
Examples:
terminer rollback ./recipe.yaml
terminer rollback /Users/sample-user/recipe.yaml
terminer rollback https://example.com/recipe.yaml
terminer rollback zsh-starter
terminer rollback -f ./recipe.yaml
terminer rollback --file /Users/sample-user/recipe.yml
terminer rollback -u https://example.com/recipe.yaml
terminer rollback --url http://foo.bar/recipe.yml
`,
Args: validateInstallRollbackArgs,
RunE: runRollback,
Args: recipecmd.ValidateArgs,
RunE: recipecmd.Run(recipecmd.Rollback),
DisableFlagsInUseLine: true,
}

func init() {
recipecmd.SupportFlags(rollbackCmd)
rootCmd.AddCommand(rollbackCmd)
}

func runRollback(cmd *cobra.Command, args []string) error {
p := printer.New()
i, err := setupInstaller(args[0], p)
if err != nil {
return err
}

err = i.Rollback()
p.Result(err)

return nil
}
49 changes: 0 additions & 49 deletions cmd/rollback_test.go

This file was deleted.

Loading

0 comments on commit e2f38f2

Please sign in to comment.