Skip to content

Commit ff413f9

Browse files
authored
Add binary to list command (#71)
1 parent 8a7633c commit ff413f9

6 files changed

Lines changed: 53 additions & 6 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
* No need for `sudo`.
4141
* Just a single binary with 0 dependencies.
4242
* Portable [`Stewfile`](https://github.com/marwanhawari/stew/blob/main/examples/Stewfile) with optional pinned versioning.
43-
* Headless batch installs from a `Stewfile.lock.json` file.
43+
* Headless batch installs from a [`Stewfile.lock.json`](https://github.com/marwanhawari/stew/blob/main/examples/Stewfile.lock.json) file.
4444

4545
![demo](https://github.com/marwanhawari/stew/raw/main/assets/demo.gif)
4646

cmd/list.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,19 @@ package cmd
22

33
import (
44
"fmt"
5+
"os"
56

7+
"github.com/gookit/color"
8+
"github.com/marwanhawari/stew/constants"
69
stew "github.com/marwanhawari/stew/lib"
10+
"golang.org/x/term"
711
)
812

913
// List is executed when you run `stew list`
1014
func List(cliTagsFlag bool) {
15+
if !term.IsTerminal(int(os.Stdout.Fd())) {
16+
color.Disable()
17+
}
1118

1219
userOS, userArch, _, systemInfo, err := stew.Initialize()
1320
stew.CatchAndExit(err)
@@ -24,12 +31,13 @@ func List(cliTagsFlag bool) {
2431
for _, pkg := range lockFile.Packages {
2532
switch pkg.Source {
2633
case "other":
27-
fmt.Println(pkg.URL)
34+
fmt.Println(constants.GreenColor(pkg.Binary+":") + pkg.URL)
2835
case "github":
36+
defaultLine := constants.GreenColor(pkg.Binary+":") + pkg.Owner + "/" + pkg.Repo
2937
if cliTagsFlag {
30-
fmt.Println(pkg.Owner + "/" + pkg.Repo + "@" + pkg.Tag)
38+
fmt.Println(defaultLine + "@" + pkg.Tag)
3139
} else {
32-
fmt.Println(pkg.Owner + "/" + pkg.Repo)
40+
fmt.Println(defaultLine)
3341
}
3442
}
3543
}

constants/constants.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ var RegexGithub = `(?i)^[A-Za-z0-9\-]+\/[A-Za-z0-9\_\.\-]+(@.+)?$`
4444
var RegexGithubSearch = `(?i)^[A-Za-z0-9\_\.\-\/\:]+$`
4545

4646
// RegexURL is a regular express for valid URLs
47-
var RegexURL = `(http|ftp|https):\/\/([\w_-]+(?:(?:\.[\w_-]+)+))([\w.,@?^=%&:\/~+#-]*[\w@?^=%&\/~+#-])`
47+
var RegexURL = `^(http|ftp|https):\/\/([\w_-]+(?:(?:\.[\w_-]+)+))([\w.,@?^=%&:\/~+#-]*[\w@?^=%&\/~+#-])`
4848

4949
// RegexChecksum is a regular expression for matching checksum files
5050
var RegexChecksum = `\.(sha(256|512)(sum)?)$`

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ require (
99
github.com/mholt/archiver v3.1.1+incompatible
1010
github.com/schollz/progressbar/v3 v3.14.2
1111
github.com/urfave/cli v1.22.14
12+
golang.org/x/term v0.19.0
1213
)
1314

1415
require (
@@ -31,6 +32,5 @@ require (
3132
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 // indirect
3233
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
3334
golang.org/x/sys v0.19.0 // indirect
34-
golang.org/x/term v0.19.0 // indirect
3535
golang.org/x/text v0.14.0 // indirect
3636
)

lib/util.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,11 +215,18 @@ func ParseCLIInput(cliInput string) (PackageData, error) {
215215
if err != nil {
216216
return PackageData{}, err
217217
}
218+
219+
splitCliInput := strings.SplitN(cliInput, ":", 2)
220+
218221
var parsedInput PackageData
219222
if reGithub.MatchString(cliInput) {
220223
parsedInput, err = parseGithubInput(cliInput)
221224
} else if reURL.MatchString(cliInput) {
222225
parsedInput, err = parseURLInput(cliInput)
226+
} else if len(splitCliInput) == 2 && reGithub.MatchString(splitCliInput[1]) {
227+
parsedInput, err = parseGithubInput(splitCliInput[1])
228+
} else if len(splitCliInput) == 2 && reURL.MatchString(splitCliInput[1]) {
229+
parsedInput, err = parseURLInput(splitCliInput[1])
223230
} else {
224231
return PackageData{}, UnrecognizedInputError{}
225232
}

lib/util_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,38 @@ func TestParseCLIInput(t *testing.T) {
465465
want: PackageData{},
466466
wantErr: true,
467467
},
468+
{
469+
name: "test5",
470+
args: args{
471+
cliInput: "a/b/c",
472+
},
473+
want: PackageData{},
474+
wantErr: true,
475+
},
476+
{
477+
name: "test6",
478+
args: args{
479+
cliInput: "ppath:marwanhawari/ppath",
480+
},
481+
want: PackageData{
482+
Source: "github",
483+
Owner: "marwanhawari",
484+
Repo: "ppath",
485+
},
486+
wantErr: false,
487+
},
488+
{
489+
name: "test7",
490+
args: args{
491+
cliInput: "ppath:https://github.com/marwanhawari/ppath/releases/download/v0.0.3/ppath-v0.0.3-darwin-arm64.tar.gz",
492+
},
493+
want: PackageData{
494+
Source: "other",
495+
Asset: "ppath-v0.0.3-darwin-arm64.tar.gz",
496+
URL: "https://github.com/marwanhawari/ppath/releases/download/v0.0.3/ppath-v0.0.3-darwin-arm64.tar.gz",
497+
},
498+
wantErr: false,
499+
},
468500
}
469501
for _, tt := range tests {
470502
t.Run(tt.name, func(t *testing.T) {

0 commit comments

Comments
 (0)