From 8dd8d83a2374d5e568e06b8357b0d1a6589491b8 Mon Sep 17 00:00:00 2001 From: Darrel Herbst Date: Wed, 1 Jan 2020 09:49:14 -0500 Subject: [PATCH] Added stations command --- README.md | 11 ++++++++++- cmd/septa/septa.go | 12 +++++++----- cmd/septa/station.go | 15 +++++++++++++++ station.go | 5 +++-- 4 files changed, 35 insertions(+), 8 deletions(-) create mode 100644 cmd/septa/station.go diff --git a/README.md b/README.md index 7abf25a..6ed17f7 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,16 @@ Returns the next to arrive between the src and dest stations. ### septa stations -TODO: Will list the stations. +Returns the list of stations + + $ septa stations + + 9th St + 30th Street Station + 49th St + Airport Terminal A + Airport Terminal B + ... ### Alerts diff --git a/cmd/septa/septa.go b/cmd/septa/septa.go index 09dff4e..5b4db61 100644 --- a/cmd/septa/septa.go +++ b/cmd/septa/septa.go @@ -12,9 +12,10 @@ var funcMap map[string]func(context.Context) func init() { funcMap = map[string]func(context.Context){ - "help": Usage, - "next": NextToArrive, - "version": Version, + "help": Usage, + "next": NextToArrive, + "stations": Stations, + "version": Version, } } @@ -28,8 +29,9 @@ func Usage(ctx context.Context) { fmt.Printf(` Usage: -septa next [from-station] [to-station] -septa version ; prints the commit version +septa stations [pattern] ; list stations, or match pattern +septa next [from-station] [to-station] ; show the next to arrive +septa version ; prints the commit version `) } diff --git a/cmd/septa/station.go b/cmd/septa/station.go new file mode 100644 index 0000000..546fe2f --- /dev/null +++ b/cmd/septa/station.go @@ -0,0 +1,15 @@ +package main + +import ( + "context" + "fmt" + + "github.com/dherbst/septa" +) + +// Stations command lists the stations that acceptable for Next To Arrive. +func Stations(ctx context.Context) { + for _, v := range septa.Stations { + fmt.Printf("%v\n", v) + } +} diff --git a/station.go b/station.go index 60a8d78..e2c0787 100644 --- a/station.go +++ b/station.go @@ -1,6 +1,7 @@ package septa -var stations = []string{ +// Stations is the list of valid station names for next to arrive +var Stations = []string{ "9th St", "30th Street Station", "49th St", @@ -160,7 +161,7 @@ var stations = []string{ // IsValidStation returns whether the station is a valid station. func IsValidStation(station string) bool { - for _, v := range stations { + for _, v := range Stations { if station == v { return true }