Skip to content

Commit

Permalink
feat: add show sub-command
Browse files Browse the repository at this point in the history
  • Loading branch information
5n7-sk committed Jan 17, 2021
1 parent 61c77f1 commit ed01137
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 6 deletions.
37 changes: 37 additions & 0 deletions cli/cli_show.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package cli

import (
"fmt"

"github.com/skmatz/vin"
)

// ShowBinDir shows the path to the bin directory.
func (c *CLI) ShowBinDir() error {
vinDir, err := vin.DefaultVinDir()
if err != nil {
return err
}

v, err := vin.New(vinDir)
if err != nil {
return err
}
fmt.Println(v.BinDir())
return nil
}

// ShowTmpDir shows the path to the tmp directory.
func (c *CLI) ShowTmpDir() error {
vinDir, err := vin.DefaultVinDir()
if err != nil {
return err
}

v, err := vin.New(vinDir)
if err != nil {
return err
}
fmt.Println(v.TmpDir())
return nil
}
15 changes: 15 additions & 0 deletions cmd/vin/cmd/cmd_show.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package cmd

import (
"github.com/spf13/cobra"
)

var showCmd = &cobra.Command{
Use: "show",
Short: "Show any information",
Long: "Show any information.",
}

func init() {
rootCmd.AddCommand(showCmd)
}
22 changes: 22 additions & 0 deletions cmd/vin/cmd/cmd_show_bin.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 runShowBin(cmd *cobra.Command, args []string) error {
c := cli.New()
return c.ShowBinDir()
}

var showBinCmd = &cobra.Command{
Use: "bin",
Short: "Show the path to the bin directory",
Long: "Show the path to the bin directory.",
RunE: runShowBin,
}

func init() {
showCmd.AddCommand(showBinCmd)
}
22 changes: 22 additions & 0 deletions cmd/vin/cmd/cmd_show_tmp.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 runShowTmp(cmd *cobra.Command, args []string) error {
c := cli.New()
return c.ShowTmpDir()
}

var showTmpCmd = &cobra.Command{
Use: "tmp",
Short: "Show the path to the tmp directory",
Long: "Show the path to the tmp directory.",
RunE: runShowTmp,
}

func init() {
showCmd.AddCommand(showTmpCmd)
}
4 changes: 2 additions & 2 deletions install.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (v *Vin) download(app App, url string, wrapper ReadCloserWrapper) (string,
return "", fmt.Errorf("http response not OK: %d", resp.StatusCode)
}

tmpDir, err := ioutil.TempDir(v.tmpDir(), "")
tmpDir, err := ioutil.TempDir(v.TmpDir(), "")
if err != nil {
return "", err
}
Expand Down Expand Up @@ -73,7 +73,7 @@ func (v *Vin) place(app App, src string) error {
if app.Name == "" {
app.Name = filepath.Base(src)
}
dst := filepath.Join(v.binDir(), app.Name)
dst := filepath.Join(v.BinDir(), app.Name)
if err := os.Rename(src, dst); err != nil {
return err
}
Expand Down
8 changes: 4 additions & 4 deletions vin.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ func DefaultVinDir() (string, error) {
return filepath.Join(home, ".vin"), nil
}

func (v *Vin) binDir() string {
func (v *Vin) BinDir() string {
return filepath.Join(v.vinDir, "bin")
}

func (v *Vin) tmpDir() string {
func (v *Vin) TmpDir() string {
return filepath.Join(v.vinDir, "tmp")
}

Expand Down Expand Up @@ -106,11 +106,11 @@ func New(vinDir string) (*Vin, error) {
vinDir: vinDir,
}

if err := os.MkdirAll(v.binDir(), os.ModePerm); err != nil {
if err := os.MkdirAll(v.BinDir(), os.ModePerm); err != nil {
return nil, err
}

if err := os.MkdirAll(v.tmpDir(), os.ModePerm); err != nil {
if err := os.MkdirAll(v.TmpDir(), os.ModePerm); err != nil {
return nil, err
}
return &v, nil
Expand Down

0 comments on commit ed01137

Please sign in to comment.