Skip to content

Commit

Permalink
feat: add example sub-command
Browse files Browse the repository at this point in the history
  • Loading branch information
5n7-sk committed Dec 14, 2020
1 parent 4ff52f3 commit 3d4c18d
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 7 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@ First, put the following TOML file in `~/.config/vin/vin.toml`.
repo = "cli/cli"
```

You can set this with the following command.

```console
mkdir -p ~/.config/vin
vin example > ~/.config/vin/vin.toml
```

Yes, all you have to do is run the following command.

```console
Expand Down
14 changes: 7 additions & 7 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,25 @@ import (
// App represents an application.
type App struct {
// Repo is the GitHub repository name in "owner/repo" format.
Repo string `toml:"repo"`
Repo string `toml:"repo,omitempty"`

// Tag is the tag on GitHub.
Tag string `toml:"tag"`
Tag string `toml:"tag,omitempty"`

// Keywords is a list of keywords for selecting suitable assets from multiple assets.
Keywords []string `toml:"keywords"`
Keywords []string `toml:"keywords,omitempty"`

// Name is the name of the executable file.
Name string `toml:"name"`
Name string `toml:"name,omitempty"`

// Hosts is a list of host names.
Hosts []string `toml:"hosts"`
Hosts []string `toml:"hosts,omitempty"`

// Priority is the priority of the application.
Priority int `toml:"priority"`
Priority int `toml:"priority,omitempty"`

// Command is the command to run after installation.
Command string `toml:"command"`
Command string `toml:"command,omitempty"`

release *github.RepositoryRelease
}
Expand Down
17 changes: 17 additions & 0 deletions cli/cli.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cli

import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
Expand All @@ -12,6 +13,7 @@ import (
"github.com/AlecAivazis/survey/v2"
"github.com/fatih/color"
multierror "github.com/hashicorp/go-multierror"
"github.com/naoina/toml"
"github.com/skmatz/vin"
"github.com/vbauerster/mpb/v5"
"golang.org/x/sync/errgroup"
Expand Down Expand Up @@ -188,6 +190,21 @@ func (c *CLI) Clean() error {
return nil
}

// Example shows a config example.
func (c *CLI) Example() error {
v := vin.Vin{
Apps: []vin.App{{
Repo: "cli/cli",
}},
}
var buf bytes.Buffer
if err := toml.NewEncoder(&buf).Encode(v); err != nil {
return err
}
fmt.Print(buf.String())
return nil
}

const tokenGenerateURL = "https://github.com/settings/tokens/new?description=Vin" //nolint:gosec

// AskGitHubAccessToken prompts for the GitHub access token.
Expand Down
22 changes: 22 additions & 0 deletions cmd/vin/cmd/cmd_example.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package cmd

import (
"github.com/skmatz/vin/cli"
"github.com/spf13/cobra"
)

func runExample(cmd *cobra.Command, args []string) error {
c := cli.New()
return c.Example()
}

var exampleCmd = &cobra.Command{
Use: "example",
Short: "Show a config example",
Long: "Show a config example.",
RunE: runExample,
}

func init() {
rootCmd.AddCommand(exampleCmd)
}
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ require (
github.com/google/go-github v17.0.0+incompatible
github.com/google/go-querystring v1.0.0 // indirect
github.com/hashicorp/go-multierror v1.0.0
github.com/kylelemons/godebug v1.1.0 // indirect
github.com/mholt/archiver/v3 v3.5.0
github.com/naoina/go-stringutil v0.1.0 // indirect
github.com/naoina/toml v0.1.1
github.com/spf13/cobra v1.1.1
github.com/vbauerster/mpb/v5 v5.3.0
golang.org/x/oauth2 v0.0.0-20201109201403-9fd604954f58
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@ github.com/kr/pty v1.1.4 h1:5Myjjh3JY/NaAi4IsUbHADytDyl1VE1Y9PXDlL+P/VQ=
github.com/kr/pty v1.1.4/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
Expand Down Expand Up @@ -233,6 +235,10 @@ github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/naoina/go-stringutil v0.1.0 h1:rCUeRUHjBjGTSHl0VC00jUPLz8/F9dDzYI70Hzifhks=
github.com/naoina/go-stringutil v0.1.0/go.mod h1:XJ2SJL9jCtBh+P9q5btrd/Ylo8XwT/h1USek5+NqSA0=
github.com/naoina/toml v0.1.1 h1:PT/lllxVVN0gzzSqSlHEmP8MJB4MY2U7STGxiouV4X8=
github.com/naoina/toml v0.1.1/go.mod h1:NBIhNtsFMo3G2szEBne+bO4gS192HuIYRqfvOWb4i1E=
github.com/nwaples/rardecode v1.1.0 h1:vSxaY8vQhOcVr4mm5e8XllHWTiM4JF507A0Katqw7MQ=
github.com/nwaples/rardecode v1.1.0/go.mod h1:5DzqNKiOdpKKBH87u8VlvAnPZMXcGRhxWkRpHbbfGS0=
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
Expand Down

0 comments on commit 3d4c18d

Please sign in to comment.