Skip to content

Commit

Permalink
Support user, repository, language options
Browse files Browse the repository at this point in the history
  • Loading branch information
sona-tar committed Oct 26, 2014
1 parent 975161d commit 9185233
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
14 changes: 13 additions & 1 deletion ghs.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@ var version = "0.0.1"

func main() {
args, opts := GhsOptionParser()
repos := SearchRepository(opts.Sort, opts.Order, args[0])

query := args[0]
if opts.Language != "" {
query += " language:" + opts.Language
}
if opts.User != "" {
query += " user:" + opts.User
}
if opts.Repository != "" {
query += " repo:" + opts.Repository
}

repos := SearchRepository(opts.Sort, opts.Order, query)
PrintRepository(repos)
}
13 changes: 10 additions & 3 deletions option.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ import (
)

type GhsOptions struct {
Sort string `short:"s" long:"sort" description:"The sort field. 'stars', 'forks', or 'updated'." default:"best match"`
Order string `short:"o" long:"order" description:"The sort order. 'asc' or 'desc'." default:"desc"`
Version bool `short:"v" long:"version" description:"print version infomation and exit."`
Sort string `short:"s" long:"sort" description:"The sort field. 'stars', 'forks', or 'updated'." default:"best match"`
Order string `short:"o" long:"order" description:"The sort order. 'asc' or 'desc'." default:"desc"`
Language string `short:"l" long:"language" description:"searches repositories based on the language they’re written in."`
User string `short:"u" long:"user" description:"limits searches to a specific user name."`
Repository string `short:"r" long:"repo" description:"limits searches to a specific repository."`
Version bool `short:"v" long:"version" description:"print version infomation and exit."`
}

func GhsOptionParser() ([]string, GhsOptions) {
Expand All @@ -37,6 +40,7 @@ func GhsOptionParser() ([]string, GhsOptions) {
printGhsHelp(parser)
os.Exit(1)
}

return args, opts
}

Expand All @@ -46,6 +50,9 @@ func printGhsOption(args []string, opts GhsOptions) {
debug.Printf("cmd option sort = %s\n", opts.Sort)
debug.Printf("cmd option order = %s\n", opts.Order)

debug.Printf("cmd option language = %s\n", opts.Language)
debug.Printf("cmd option User = %s\n", opts.User)
debug.Printf("cmd option Repository = %s\n", opts.Repository)
debug.Printf("cmd option Version = %s\n", opts.Version)
}

Expand Down

0 comments on commit 9185233

Please sign in to comment.