Skip to content

Commit

Permalink
Merge pull request #28 from gkze/gk-add-from-list
Browse files Browse the repository at this point in the history
Add support for adding from list (stdin or file); upgrade modules
  • Loading branch information
gkze authored Jan 29, 2021
2 parents 1472d86 + 406302b commit e3262a6
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 76 deletions.
39 changes: 33 additions & 6 deletions cmd/stars/stars.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"errors"
"fmt"
"io"
"net/url"
"os"
"strconv"
Expand Down Expand Up @@ -66,6 +67,7 @@ func mkAddStarsCmd() *cobra.Command {
fromURL string
fromUser string
fromOrg string
fromList string
)

addStarsCmd := &cobra.Command{
Expand All @@ -74,14 +76,17 @@ func mkAddStarsCmd() *cobra.Command {
Long: "Star repositories, specified in various ways",
RunE: func(cmd *cobra.Command, args []string) error {
// Exactly one of the options must be passed
if (fromURL == "" && fromUser == "" && fromOrg == "" ||
fromURL != "" && fromUser != "" && fromOrg != "") ||
(fromURL != "" && fromUser != "") ||
(fromUser != "" && fromOrg != "") ||
(fromURL != "" && fromOrg != "") {
fromSpecifiedCount := 0

for _, source := range []string{fromURL, fromUser, fromOrg, fromList} {
if source != "" {
fromSpecifiedCount++
}
}

if fromSpecifiedCount < 1 {
return errors.New(
"Can only pass one of: -u/--from-urls, -o/--from-org, -g/--from-user",
"Can only pass one of: -u/--from-urls, -o/--from-org, -g/--from-user, -l/--from-list",
)
}

Expand Down Expand Up @@ -118,6 +123,25 @@ func mkAddStarsCmd() *cobra.Command {
return sm.StarRepositoriesFromUser(fromUser, addMonths, concurrency)
}

if fromList != "" {
log.Infof("Attempting to read from %s\n", fromList)

var reader io.Reader
if fromList == "-" {
reader = os.Stdin
} else {
file, err := os.Open(fromList)
if err != nil {
return err
}

reader = file
}

_, err := sm.StarRepositoriesFromReader(reader, concurrency, addMonths)
return err
}

return nil
},
}
Expand All @@ -132,6 +156,9 @@ func mkAddStarsCmd() *cobra.Command {
addStarsCmd.PersistentFlags().StringVarP(
&fromUser, "from-user", "s", "", "User to add new stars from",
)
addStarsCmd.PersistentFlags().StringVarP(
&fromList, "from-list", "l", "", "List of github URLs to add new stars from",
)

return addStarsCmd
}
Expand Down
18 changes: 7 additions & 11 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,30 @@ module github.com/gkze/stars
require (
github.com/DataDog/zstd v1.4.0 // indirect
github.com/Sereal/Sereal v0.0.0-20190416075407-a9d24ede505a // indirect
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6 // indirect
github.com/asdine/storm v2.1.2+incompatible
github.com/golang/protobuf v1.4.3 // indirect
github.com/golang/snappy v0.0.1 // indirect
github.com/google/go-github/v25 v25.1.3
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.0
github.com/jdxcode/netrc v0.0.0-20201119100258-050cafb6dbe6
github.com/konsorten/go-windows-terminal-sequences v1.0.3 // indirect
github.com/pkg/browser v0.0.0-20201207095918-0426ae3fba23
github.com/pkg/browser v0.0.0-20210115035449-ce105d075bb4
github.com/scylladb/go-set v1.0.2
github.com/sirupsen/logrus v1.7.0
github.com/spf13/afero v1.5.1
github.com/spf13/cobra v1.1.1
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/testify v1.4.0
github.com/ugorji/go v1.1.4 // indirect
github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77 // indirect
go.etcd.io/bbolt v1.3.5 // indirect
go.uber.org/multierr v1.6.0
go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee // indirect
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad
golang.org/x/net v0.0.0-20201224014010-6772e930b67b // indirect
golang.org/x/oauth2 v0.0.0-20201208152858-08078c50e5b5
golang.org/x/sys v0.0.0-20210108172913-0df2131ae363 // indirect
golang.org/x/net v0.0.0-20210119194325-5f4716e94777 // indirect
golang.org/x/oauth2 v0.0.0-20210126194326-f9ce19ea3013
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c // indirect
golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf // indirect
golang.org/x/text v0.3.5 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.25.0 // indirect
gopkg.in/yaml.v2 v2.3.0 // indirect
mvdan.cc/xurls/v2 v2.2.0
)

Expand Down
Loading

0 comments on commit e3262a6

Please sign in to comment.