Compare commits
4 Commits
7d00c7b5fb
...
eaf49a4594
Author | SHA1 | Date | |
---|---|---|---|
eaf49a4594 | |||
c0439a2b90 | |||
43d6461c71 | |||
2e591d9f1c |
31
cli.go
Normal file
31
cli.go
Normal 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
|
||||
}
|
@ -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
34
repo.go
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user