Fix binary and add command
Signed-off-by: jolheiser <john.olheiser@gmail.com>pull/1/head
parent
023c95c5bb
commit
62ad64516c
|
@ -2,7 +2,7 @@ package cmd
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"gitea.com/gpm/cli/modules/config"
|
||||
"gitea.com/gpm/gpm/modules/config"
|
||||
"gitea.com/jolheiser/beaver"
|
||||
"github.com/AlecAivazis/survey/v2"
|
||||
"github.com/urfave/cli/v2"
|
||||
|
@ -25,7 +25,7 @@ var Add = cli.Command{
|
|||
func doAdd(ctx *cli.Context) error {
|
||||
|
||||
goGetQuestion := &survey.Input{
|
||||
Message: "Package go-get URL",
|
||||
Message: "Package go-get import",
|
||||
}
|
||||
var goGetAnswer string
|
||||
|
||||
|
@ -52,7 +52,7 @@ func doAdd(ctx *cli.Context) error {
|
|||
|
||||
pkg := config.Package{
|
||||
Name: nameAnswer,
|
||||
URL: goGetAnswer,
|
||||
Import: goGetAnswer,
|
||||
}
|
||||
if !ctx.Bool("force") {
|
||||
for idx, p := range config.Packages {
|
||||
|
@ -75,6 +75,7 @@ func doAdd(ctx *cli.Context) error {
|
|||
break
|
||||
}
|
||||
}
|
||||
config.Packages = append(config.Packages, pkg)
|
||||
} else {
|
||||
config.Packages = append(config.Packages, pkg)
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package cmd
|
||||
|
||||
import (
|
||||
"gitea.com/gpm/cli/modules/config"
|
||||
"gitea.com/gpm/gpm/modules/config"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
|
@ -9,7 +9,7 @@ var Flags = []cli.Flag{
|
|||
&cli.StringFlag{
|
||||
Name: "url",
|
||||
Aliases: []string{"u"},
|
||||
Usage: "gpm URL to use",
|
||||
Usage: "gpm server to use",
|
||||
Value: config.GPMURL,
|
||||
},
|
||||
}
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
package cmd
|
||||
|
||||
import (
|
||||
"gitea.com/gpm/gpm/modules/config"
|
||||
"gitea.com/jolheiser/beaver"
|
||||
"github.com/AlecAivazis/survey/v2"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
var Config = cli.Command{
|
||||
Name: "config",
|
||||
Aliases: []string{"cfg"},
|
||||
Action: doConfig,
|
||||
}
|
||||
|
||||
func doConfig(ctx *cli.Context) error {
|
||||
urlQuestion := &survey.Input{
|
||||
Message: "gpm URL",
|
||||
Default: "gpm.jolheiser.com",
|
||||
}
|
||||
var urlAnswer string
|
||||
|
||||
if err := survey.AskOne(urlQuestion, &urlAnswer); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
config.GPMURL = urlAnswer
|
||||
if err := config.Save(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
beaver.Info("gpm URL saved!")
|
||||
return nil
|
||||
}
|
|
@ -1,9 +1,8 @@
|
|||
package cmd
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"gitea.com/gpm/cli/modules/config"
|
||||
"gitea.com/gpm/gpm/modules/config"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
|
@ -15,11 +14,11 @@ var Export = cli.Command{
|
|||
|
||||
func doExport(ctx *cli.Context) error {
|
||||
|
||||
data, err := json.Marshal(config.Packages)
|
||||
export, err := config.Export()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Println(string(data))
|
||||
fmt.Println(export)
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ package cmd
|
|||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"gitea.com/gpm/cli/modules/config"
|
||||
"gitea.com/gpm/gpm/modules/config"
|
||||
"gitea.com/jolheiser/beaver"
|
||||
"github.com/AlecAivazis/survey/v2"
|
||||
"github.com/urfave/cli/v2"
|
||||
|
@ -54,6 +54,8 @@ func doGet(ctx *cli.Context) error {
|
|||
}
|
||||
url = u
|
||||
}
|
||||
|
||||
beaver.Infof("getting `%s`...", pkg)
|
||||
if err := goGet(url); err != nil {
|
||||
beaver.Error(err)
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ package cmd
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"gitea.com/gpm/cli/modules/config"
|
||||
"gitea.com/gpm/gpm/modules/config"
|
||||
"gitea.com/jolheiser/beaver"
|
||||
"github.com/AlecAivazis/survey/v2"
|
||||
"github.com/urfave/cli/v2"
|
||||
|
@ -28,7 +28,7 @@ func doRemove(ctx *cli.Context) error {
|
|||
for idx, p := range config.Packages {
|
||||
if strings.EqualFold(p.Name, pkgAnswer) {
|
||||
confirm := &survey.Confirm{
|
||||
Message: fmt.Sprintf("Are you sure you want to remove %s (%s) ?", p.Name, p.URL),
|
||||
Message: fmt.Sprintf("Are you sure you want to remove %s (%s) ?", p.Name, p.Import),
|
||||
Default: false,
|
||||
}
|
||||
var answer bool
|
||||
|
|
3
main.go
3
main.go
|
@ -1,7 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"gitea.com/gpm/cli/cmd"
|
||||
"gitea.com/gpm/gpm/cmd"
|
||||
"gitea.com/jolheiser/beaver"
|
||||
"github.com/urfave/cli/v2"
|
||||
"os"
|
||||
|
@ -22,6 +22,7 @@ func main() {
|
|||
&cmd.Remove,
|
||||
&cmd.Get,
|
||||
&cmd.Export,
|
||||
&cmd.Config,
|
||||
}
|
||||
app.Flags = cmd.Flags
|
||||
app.EnableBashCompletion = true
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package config
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"gitea.com/jolheiser/beaver"
|
||||
"github.com/BurntSushi/toml"
|
||||
|
@ -21,13 +22,13 @@ var (
|
|||
)
|
||||
|
||||
type config struct {
|
||||
GPMURL string `toml:"gpm-url"`
|
||||
Packages []Package `toml:"package"`
|
||||
GPMURL string `toml:"gpm-url" json:"gpm_url"`
|
||||
Packages []Package `toml:"package" json:"packages"`
|
||||
}
|
||||
|
||||
type Package struct {
|
||||
Name string `toml:"name"`
|
||||
URL string `toml:"url"`
|
||||
Name string `toml:"name" json:"name"`
|
||||
Import string `toml:"import" json:"import"`
|
||||
}
|
||||
|
||||
// Load on init so that CLI contexts are correctly populated
|
||||
|
@ -82,10 +83,15 @@ func Save() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func Export() (string, error) {
|
||||
data, err := json.Marshal(cfg)
|
||||
return string(data), err
|
||||
}
|
||||
|
||||
func PackageMap() map[string]string {
|
||||
pkgs := make(map[string]string)
|
||||
for _, pkg := range Packages {
|
||||
pkgs[pkg.Name] = pkg.URL
|
||||
pkgs[pkg.Name] = pkg.Import
|
||||
}
|
||||
return pkgs
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue