Skip to content

Commit

Permalink
Added stations command
Browse files Browse the repository at this point in the history
  • Loading branch information
dherbst committed Jan 1, 2020
1 parent e4d2411 commit 8dd8d83
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 8 deletions.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 7 additions & 5 deletions cmd/septa/septa.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand All @@ -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
`)

}
Expand Down
15 changes: 15 additions & 0 deletions cmd/septa/station.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
5 changes: 3 additions & 2 deletions station.go
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 8dd8d83

Please sign in to comment.