Compare commits

...

4 Commits

Author SHA1 Message Date
eaf49a4594 Make actions in internal/repos unexported
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2022-11-30 21:47:07 -08:00
c0439a2b90 Remove unused imports 2022-11-30 21:46:41 -08:00
43d6461c71 Move pkgPrompt() to cli.go 2022-11-30 21:43:52 -08:00
2e591d9f1c Remove unnecessary PkgNotFoundError 2022-11-30 21:43:10 -08:00
3 changed files with 49 additions and 52 deletions

31
cli.go Normal file
View File

@ -0,0 +1,31 @@
package main
import (
"github.com/AlecAivazis/survey/v2"
"go.arsenm.dev/lure/internal/db"
)
func pkgPrompt(options []db.Package, verb string) ([]db.Package, error) {
names := make([]string, len(options))
for i, option := range options {
names[i] = option.Repository + "/" + option.Name + " " + option.Version
}
prompt := &survey.MultiSelect{
Options: names,
Message: "Choose which package(s) to " + verb,
}
var choices []int
err := survey.AskOne(prompt, &choices)
if err != nil {
return nil, err
}
out := make([]db.Package, len(choices))
for i, choiceIndex := range choices {
out[i] = options[choiceIndex]
}
return out, nil
}

View File

@ -132,15 +132,15 @@ func Pull(ctx context.Context, gdb *genji.DB, repos []types.Repo) error {
return nil
}
type ActionType uint8
type actionType uint8
const (
ActionDelete ActionType = iota
ActionUpdate
actionDelete actionType = iota
actionUpdate
)
type Action struct {
Type ActionType
type action struct {
Type actionType
File string
}
@ -160,34 +160,34 @@ func processRepoChanges(ctx context.Context, repo types.Repo, r *git.Repository,
return err
}
var actions []Action
var actions []action
for _, fp := range patch.FilePatches() {
from, to := fp.Files()
if to == nil {
actions = append(actions, Action{
Type: ActionDelete,
actions = append(actions, action{
Type: actionDelete,
File: from.Path(),
})
} else if from == nil {
actions = append(actions, Action{
Type: ActionUpdate,
actions = append(actions, action{
Type: actionUpdate,
File: to.Path(),
})
} else {
if from.Path() != to.Path() {
actions = append(actions,
Action{
Type: ActionDelete,
action{
Type: actionDelete,
File: from.Path(),
},
Action{
Type: ActionUpdate,
action{
Type: actionUpdate,
File: to.Path(),
},
)
} else {
actions = append(actions, Action{
Type: ActionUpdate,
actions = append(actions, action{
Type: actionUpdate,
File: to.Path(),
})
}
@ -208,7 +208,7 @@ func processRepoChanges(ctx context.Context, repo types.Repo, r *git.Repository,
for _, action := range actions {
switch action.Type {
case ActionDelete:
case actionDelete:
scriptFl, err := oldCommit.File(action.File)
if err != nil {
return nil
@ -229,7 +229,7 @@ func processRepoChanges(ctx context.Context, repo types.Repo, r *git.Repository,
if err != nil {
return err
}
case ActionUpdate:
case actionUpdate:
scriptFl, err := newCommit.File(action.File)
if err != nil {
return nil

34
repo.go
View File

@ -22,7 +22,6 @@ import (
"os"
"path/filepath"
"github.com/AlecAivazis/survey/v2"
"github.com/pelletier/go-toml/v2"
"github.com/urfave/cli/v2"
"go.arsenm.dev/logger/log"
@ -33,14 +32,6 @@ import (
"golang.org/x/exp/slices"
)
type PkgNotFoundError struct {
pkgName string
}
func (p PkgNotFoundError) Error() string {
return "package '" + p.pkgName + "' could not be found in any repository"
}
func addrepoCmd(c *cli.Context) error {
name := c.String("name")
repoURL := c.String("url")
@ -121,28 +112,3 @@ func refreshCmd(c *cli.Context) error {
}
return nil
}
func pkgPrompt(options []db.Package, verb string) ([]db.Package, error) {
names := make([]string, len(options))
for i, option := range options {
names[i] = option.Repository + "/" + option.Name + " " + option.Version
}
prompt := &survey.MultiSelect{
Options: names,
Message: "Choose which package(s) to " + verb,
}
var choices []int
err := survey.AskOne(prompt, &choices)
if err != nil {
return nil, err
}
out := make([]db.Package, len(choices))
for i, choiceIndex := range choices {
out[i] = options[choiceIndex]
}
return out, nil
}