Skip to content

Commit 288accc

Browse files
committed
Merge pull request exercism#63 from Tonkpils/filter-current
Allow filtering current by language
2 parents 96627c6 + 09d9462 commit 288accc

1 file changed

Lines changed: 20 additions & 2 deletions

File tree

main.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ func main() {
2424
ShortName: "c",
2525
Usage: "Show the current assignments",
2626
Action: func(c *cli.Context) {
27+
var language string
28+
argc := len(c.Args())
29+
if argc != 0 && argc != 1 {
30+
fmt.Println("Usage: exercism current\n or: exercism current LANGUAGE")
31+
return
32+
}
33+
2734
config, err := configuration.FromFile(c.GlobalString("config"))
2835
if err != nil {
2936
fmt.Println("Are you sure you are logged in? Please login again.")
@@ -35,10 +42,21 @@ func main() {
3542
return
3643
}
3744

38-
fmt.Println("Current Assignments")
45+
if argc == 1 {
46+
language = c.Args()[0]
47+
fmt.Println("Current Assignments for", strings.Title(language))
48+
} else {
49+
fmt.Println("Current Assignments")
50+
}
3951

4052
for _, a := range currentAssignments {
41-
fmt.Printf("%v: %v\n", strings.Title(a.Track), a.Slug)
53+
if argc == 1 {
54+
if strings.ToLower(language) == strings.ToLower(a.Track) {
55+
fmt.Printf("%v: %v\n", strings.Title(a.Track), a.Slug)
56+
}
57+
} else {
58+
fmt.Printf("%v: %v\n", strings.Title(a.Track), a.Slug)
59+
}
4260
}
4361
},
4462
},

0 commit comments

Comments
 (0)