~mil/mobroute

e2e0eb3c1d3021df1f957a91295236ea28691f24 — Miles Alan 2 months ago 419d213
Improve usage message to include examples for route subcommand
2 files changed, 28 insertions(+), 21 deletions(-)

M cli/const.go
M cli/mobroutecli.go
M cli/const.go => cli/const.go +19 -21
@@ 1,35 1,33 @@
package main

const (
	subcmdRouteExamples = `
  - Brussels Routing Example:
    {"route_params":{"feed_ids":[1088],"from":[50.85728,4.351426],"to":[50.83214,4.350534],"transfer_categories":["f","i"],"output_formats":["legs","diagnostics","mapurl","request"]}}

  - Krakow Routing Example:
    {"route_params":{"feed_ids":[1270],"from":[50.012338,19.88192],"to":[50.08785,20.02387],"transfer_categories":["f","i"],"output_formats":["legs","diagnostics","mapurl","request"]}}

  - NYC Routing Example:
    {"route_params":{"feed_ids":[516],"from":[40.70940,-74.00537],"to":[40.72879,-73.95215],"transfer_categories":["f","i"],"output_formats":["legs","diagnostics","mapurl","request"]}}
		`
var (
	subcmdRouteExamples = map[string]string{
		"Brussels Routing Example": `mobroute route -rp '{"route_params":{"feed_ids":[1088],"from":[50.85728,4.351426],"to":[50.83214,4.350534],"transfer_categories":["f","i"],"output_formats":["legs","diagnostics","mapurl","request"]}}'`,
		"Krakow Routing Example":   `mobroute route -rp '{"route_params":{"feed_ids":[1270],"from":[50.012338,19.88192],"to":[50.08785,20.02387],"transfer_categories":["f","i"],"output_formats":["legs","diagnostics","mapurl","request"]}}'`,
		"NYC Routing Example":      `mobroute route -rp '{"route_params":{"feed_ids":[516],"from":[40.70940,-74.00537],"to":[40.72879,-73.95215],"transfer_categories":["f","i"],"output_formats":["legs","diagnostics","mapurl","request"]}}'`,
	}
)

const (
	subcmdRouteDoc = `
JSON Parameters for oneshot route subcommand, should be in format of: {"route_params": {"feed_ids": [516],...}}

Valid route parameters:
  - feed_ids: Array of feed IDs (MDBID) to use for routing requests (default: [516])
  - from: Object with two float properties, lat & lon (default: [40.70940, -74.00537])
  - to: Object with two float properties, lat & lon (default: [40.72879, -73.95215])
  - time: Datetime to depart from trip, if unset defaults to current time / now (default: null)
Required route parameters:
  - feed_ids: Array of integer feed IDs (MDBID) to use for routing requests
  - from: Array of two floats; [lat, lon]
  - to: Array of two floats; [lat, lon]
  - time: Datetime at which route should depart in RFC3339 format
  - transfer_categories: Array of transfers categories to load - "f" for feed, "i" for implicit, "g" for generated, e.g. ["f", "i"]
  - output_formats: Array of formats for the output may include - ["legs", "geojson", "diagnostics", "mapurl", "request"]

Optional route parameters:
  - max_walk_seconds: Maximum seconds walking distance on start/end of trip to get to/from origin/destination stops (default: 1200)
  - max_trip_seconds: Maximum seconds the entire route/trip can take (default: 14400)
  - min_transfer_seconds: Minimum seconds each transfer in the route can take (default: 180)
  - max_transfer_seconds: Maximum seconds each transfer in the route can take (default: 2400)
  - max_n_transfers: Maximum number of transfers a route can contain (default: 20)
  - walkspeed_km_hr: Ratio of kilometers per hour the user walk (default: 4.5)
  - transfer_categories: Array of transfers categories to load - "f" for feed, "i" for implicit, "g" for generated (default: ["f", "i"])
  - cache_dir: Directory to store sqlite db, defaults to ~/.cache/mobroute if null (default: null)
  - output_formats: Array of formats for the output may include - "legs", "geojson", "diagnostics", "mapurl", "request" (default: ["legs"])
		`
`

	subcmdMobsqlDoc = `JSON Parameters for mobsql subcommands`
	subcmdMobsqlDoc = `JSON Parameters for oneshot mobsql subcommand, should be in format of: {}.`
)

M cli/mobroutecli.go => cli/mobroutecli.go +9 -0
@@ 45,6 45,15 @@ func main() {

func cmdRoute(flagRouteSet *flag.FlagSet, flagRouteParams *string) {
	var routeParams mobroute.OneshotRouteRequest
	flagRouteSet.Usage = func() {
		fmt.Fprintf(os.Stderr, "Usage of %s:\n", os.Args[0])
		flagRouteSet.PrintDefaults()
		fmt.Fprintf(os.Stderr, "\nExamples:\n")
		for exName, exCmd := range subcmdRouteExamples {
			fmt.Fprintf(os.Stderr, "  %s:\n    %s\n", exName, exCmd)
		}
		fmt.Fprintf(os.Stderr, "\n")
	}
	flagRouteSet.Parse(os.Args[2:])
	if *flagRouteParams == "" {
		flagRouteSet.Usage()