Skip to content

Commit dc299e2

Browse files
authored
Updates (#26)
1 parent 234cd01 commit dc299e2

13 files changed

Lines changed: 147 additions & 122 deletions

File tree

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,6 @@ task docs
165165
Inno Setup: <https://jrsoftware.org/isdl.php>
166166

167167
```shell
168-
task pathmgr
169168
task inno
170169
```
171170

Taskfile.yml

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ env:
66

77
tasks:
88
goup:
9-
aliases: [goget, tidy]
9+
aliases: [go, tidy]
1010
cmd: |
1111
go get -u
1212
go mod tidy
@@ -55,11 +55,14 @@ tasks:
5555
unzip dist/pathmgr.zip -d dist/PathMgr
5656
5757
install:
58+
vars:
59+
SOURCE_NAME: install-release
60+
TARGET_NAME: ir
5861
cmd: |
5962
go build
60-
mv install-release "${HOME}/bin/ir"
61-
which ir
62-
ir -V
63+
mv -f {{.SOURCE_NAME}} "${HOME}/bin/{{.TARGET_NAME}}"
64+
which {{.TARGET_NAME}}
65+
{{.TARGET_NAME}} -V
6366
6467
vhs:*:
6568
desc: Create VHS Tape
@@ -68,3 +71,18 @@ tasks:
6871
cmd: |
6972
echo "Creating Tape - assets/{{.TAPE_FILE}}.tape"
7073
vhs "assets/{{.TAPE_FILE}}.tape"
74+
75+
build:*:*:
76+
desc: Build OS:ARCH
77+
vars:
78+
OS: "{{index .MATCH 0}}"
79+
ARCH: "{{index .MATCH 1}}"
80+
requires:
81+
vars:
82+
- name: OS
83+
enum: [darwin, linux, windows]
84+
- name: ARCH
85+
enum: [amd64, arm64, "386"]
86+
cmd: |
87+
echo "Building: {{.OS}} / {{.ARCH}}"
88+
GOOS={{.OS}} GOARCH={{.ARCH}} goreleaser build --snapshot --clean --single-target {{.CLI_ARGS}}

cmd/config.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package cmd
2+
3+
import (
4+
"github.com/charmbracelet/log"
5+
"github.com/confluentinc/go-editor"
6+
"github.com/smashedr/install-release/internal/styles"
7+
"github.com/spf13/cobra"
8+
"github.com/spf13/viper"
9+
)
10+
11+
var configCmd = &cobra.Command{
12+
Use: "config",
13+
Aliases: []string{"c", "co", "con", "cfg"},
14+
Short: "Edit configuration settings",
15+
Long: "Edit configuration settings.",
16+
Run: func(cmd *cobra.Command, args []string) {
17+
binPath := viper.GetString("bin")
18+
log.Debug("configCmd", "args", args, "binPath", binPath)
19+
20+
file := viper.ConfigFileUsed()
21+
log.Infof("viper.ConfigFileUsed(): %v", file)
22+
edit := editor.NewEditor()
23+
if err := edit.Launch(file); err != nil {
24+
log.Fatal(err)
25+
}
26+
styles.PrintS("Config Saved", "")
27+
},
28+
}
29+
30+
func init() {
31+
rootCmd.AddCommand(configCmd)
32+
}

cmd/info.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ var infoCmd = &cobra.Command{
2121
Run: func(cmd *cobra.Command, args []string) {
2222
binPath := viper.GetString("bin")
2323
//sumFlag, _ := cmd.Flags().GetBool("summary")
24-
log.Debug("infoCmd:", "args", args, "binPath", binPath)
24+
log.Debug("infoCmd", "args", args, "binPath", binPath)
2525

2626
if len(args) >= 1 && strings.Contains(args[0], "/") {
2727
owner, repo, err := parseRepository(args[0])

cmd/install.go

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"net/http"
1919
"os"
2020
"path/filepath"
21+
"regexp"
2122
"runtime"
2223
"strings"
2324
"time"
@@ -33,7 +34,7 @@ func runInstall(cmd *cobra.Command, args []string) error { // NOSONAR
3334
cmd.SilenceUsage = true // set here so subcommands do not silence usage
3435
var err error
3536
binPath := viper.GetString("bin")
36-
log.Debug("runInstall:", "args", args, "binPath", binPath)
37+
log.Debug("runInstall", "args", args, "binPath", binPath)
3738
skipPrompts, _ := cmd.Flags().GetBool("yes")
3839
assetName, _ := cmd.Flags().GetString("asset")
3940
destName, _ := cmd.Flags().GetString("name")
@@ -130,14 +131,12 @@ func runInstall(cmd *cobra.Command, args []string) error { // NOSONAR
130131
log.Infof("tmpFile: %v", tmpFile.Name())
131132

132133
// Write Download to File
133-
_, err = io.Copy(tmpFile, rc)
134-
if err != nil {
134+
if _, err := io.Copy(tmpFile, rc); err != nil {
135135
return fmt.Errorf("write File error: %w", err)
136136
}
137137

138138
// Seek Back to Start of File
139-
_, err = tmpFile.Seek(0, 0)
140-
if err != nil {
139+
if _, err := tmpFile.Seek(0, 0); err != nil {
141140
return fmt.Errorf("seek error: %w", err)
142141
}
143142

@@ -198,8 +197,7 @@ func runInstall(cmd *cobra.Command, args []string) error { // NOSONAR
198197
return nil
199198
}).
200199
Value(&destName)
201-
err = form.Run()
202-
if err != nil {
200+
if err := form.Run(); err != nil {
203201
log.Fatalf("Prompt failed %v", err)
204202
}
205203
log.Debugf("4 destName: %v", destName)
@@ -228,8 +226,7 @@ func runInstall(cmd *cobra.Command, args []string) error { // NOSONAR
228226
return fmt.Errorf("failed to read file: %w", err)
229227
}
230228
// Write to destination with executable permissions
231-
err = os.WriteFile(destPath, data, 0755)
232-
if err != nil {
229+
if err := os.WriteFile(destPath, data, 0755); err != nil {
233230
return fmt.Errorf("failed to write file: %w", err)
234231
}
235232
}
@@ -401,3 +398,13 @@ func ensureWinExt(destName string) string {
401398
}
402399
return destName
403400
}
401+
402+
func parseRepository(repository string) (owner, repo string, err error) {
403+
var repoPattern = regexp.MustCompile(`^[a-zA-Z0-9_.-]+/[a-zA-Z0-9_.-]+$`)
404+
405+
if !repoPattern.MatchString(repository) {
406+
return "", "", fmt.Errorf("repository must be in format: owner/repo")
407+
}
408+
split := strings.Split(repository, "/")
409+
return split[0], split[1], nil
410+
}

cmd/list.go

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ import (
1010
)
1111

1212
var listCmd = &cobra.Command{
13-
Use: "list [name]",
13+
Use: "list",
1414
Aliases: []string{"l", "li", "lis", "ls"},
1515
Short: "List installed binaries",
1616
Long: "List installed binaries.",
1717
Run: func(cmd *cobra.Command, args []string) {
1818
binPath := viper.GetString("bin")
19-
log.Debug("listCmd:", "args", args, "binPath", binPath)
19+
log.Debug("listCmd", "args", args, "binPath", binPath)
2020

2121
entries, err := os.ReadDir(binPath)
2222
log.Infof("entries: %v", entries)
@@ -28,19 +28,6 @@ var listCmd = &cobra.Command{
2828
return
2929
}
3030

31-
//width, height, err := term.GetSize(os.Stdout.Fd())
32-
//if err != nil {
33-
// log.Warn(err)
34-
// width = 80
35-
//}
36-
//log.Info("GetSize:", "width", width, "height", height)
37-
38-
////styles.PrintKV("Bin:", binPath)
39-
//fmt.Printf(styles.Head.Width(width).Render(fmt.Sprintf("Found %d Apps", len(entries))) + "\n")
40-
//for _, e := range entries {
41-
// fmt.Println(e.Name())
42-
//}
43-
4431
var rows [][]string
4532
for _, e := range entries {
4633
info, err := e.Info()
@@ -55,22 +42,6 @@ var listCmd = &cobra.Command{
5542
},
5643
}
5744

58-
//func listDir(path string) {
59-
// entries, err := os.ReadDir(path)
60-
// log.Infof("entries: %v", entries)
61-
// if err != nil {
62-
// fmt.Printf("Name Not Found\n")
63-
// return
64-
// }
65-
// if len(entries) == 0 {
66-
// fmt.Printf("The bin is empty: %s\n", path)
67-
// return
68-
// }
69-
// for _, e := range entries {
70-
// fmt.Println(e.Name())
71-
// }
72-
//}
73-
7445
func init() {
7546
rootCmd.AddCommand(listCmd)
7647
}

cmd/path.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@ import (
1010
"strings"
1111
)
1212

13-
//const (
14-
// PathTypeSystem = 0
15-
// PathTypeUser = 1
16-
//)
17-
1813
var pathCmd = &cobra.Command{
1914
Use: "path check/add/remove path",
2015
Aliases: []string{"p", "pa", "pat"},
@@ -24,7 +19,7 @@ var pathCmd = &cobra.Command{
2419
//Args: cobra.ExactArgs(2),
2520
Run: func(cmd *cobra.Command, args []string) {
2621
binPath := viper.GetString("bin")
27-
log.Debug("pathCmd:", "args", args, "binPath", binPath)
22+
log.Debug("pathCmd", "args", args, "binPath", binPath)
2823

2924
if os.Getenv("DOCKER") == "true" {
3025
log.Errorf("PATH does not work DOCKER.")

cmd/remove.go

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,26 @@ import (
1313
)
1414

1515
var removeCmd = &cobra.Command{
16-
Use: "remove",
16+
Use: "remove [name]",
1717
Aliases: []string{"r", "re", "rem", "rm"},
1818
Short: "Remove an installed program",
1919
Long: "Remove an installed program.",
2020
Run: func(cmd *cobra.Command, args []string) {
2121
binPath := viper.GetString("bin")
22-
log.Debug("removeCmd:", "args", args, "binPath", binPath)
22+
log.Debug("removeCmd", "args", args, "binPath", binPath)
2323
//noConfirm, _ := cmd.Flags().GetBool("yes")
2424
//log.Debug("Flags", "noConfirm", noConfirm)
25+
26+
var name string
27+
var err error
2528
if len(args) == 0 {
26-
_ = cmd.Help()
27-
return
29+
name, err = promptAsset(binPath)
30+
if err != nil {
31+
log.Fatal(err)
32+
}
33+
} else {
34+
name = args[0]
2835
}
29-
30-
name := args[0]
3136
log.Infof("name: %v", name)
3237

3338
path := filepath.Join(binPath, name)
@@ -53,23 +58,44 @@ var removeCmd = &cobra.Command{
5358
Negative("Cancel").
5459
Value(&confirm).
5560
WithTheme(huh.ThemeDracula())
56-
err := form.Run()
57-
if err != nil {
61+
if err := form.Run(); err != nil {
5862
log.Fatalf("prompt error: %v", err)
5963
}
6064
log.Infof("confirm: %v", confirm)
6165
if !confirm {
6266
return
6367
}
6468

65-
err = os.Remove(path)
66-
if err != nil {
69+
if err := os.Remove(path); err != nil {
6770
log.Fatalf("prompt error: %v", err)
6871
}
6972
styles.PrintKV("Removed:", name)
7073
},
7174
}
7275

76+
func promptAsset(binPath string) (string, error) {
77+
log.Info("promptAsset", "binPath", binPath)
78+
entries, err := os.ReadDir(binPath)
79+
if err != nil {
80+
return "", err
81+
}
82+
log.Infof("entries: %v", entries)
83+
84+
options := make([]huh.Option[string], len(entries))
85+
for i, asset := range entries {
86+
options[i] = huh.NewOption(asset.Name(), asset.Name())
87+
}
88+
var result string
89+
form := huh.NewSelect[string]().
90+
Title("Select App to Remove:").
91+
Options(options...).
92+
Value(&result)
93+
if err := form.Run(); err != nil {
94+
return result, fmt.Errorf("prompt failed: %w", err)
95+
}
96+
return result, nil
97+
}
98+
7399
func init() {
74100
rootCmd.AddCommand(removeCmd)
75101
}

0 commit comments

Comments
 (0)