Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consolidate tools into a single command-line interface #753

Merged
merged 7 commits into from
Sep 18, 2021
Merged

Conversation

dabreegster
Copy link
Collaborator

#715 has the motivation. This is a pretty massive change; feel free to just focus on cli/src/main.rs, which uses structopt.

Doc changes are at https:/a-b-street/docs/tree/cli. I'll also need to update the abstr docs/vignettes.

Github actions is creating a build now; I'll try the map and scenario importers from the UI there to sanity check everything is named correctly.


use geom::LonLat;

pub fn run(path: String) -> Result<()> {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed to take a file as a path, instead of read from STDIN. Much easier to use this as a library call from one_step_import.rs.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small nit/reminder: Path/PathBuffer are nice and should probably be preferred for this kind of thing... though maybe this method has sufficient interop to make that an undesirably cascading change.

},
/// Runs the main A/B Street importer, which manages maps and scenarios for many cities.
Import {
/// See the importer's source code for the defined flags. You should first pass a bare "--"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I gave up on defining all of the flags here, for now. :\ I need to learn more structopt to understand how to do enumerations of flags -- like if you pass --oneshot, only then does --oneshot_drive_on_left become a valid flag. Possibly the proper way to do this is simply split out two subcommands, for a "normal" import and for a one-shot.

stdin.write_all(&geojson)?;
assert!(cmd.wait()?.success());

crate::geojson_to_osmosis::run(geojson_path.clone())?;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No more running subprocesses and parsing STDOUT!

@Robinlovelace
Copy link
Contributor

Looking like a mega refactor, look forward to giving it a spin!

@dabreegster
Copy link
Collaborator Author

Testing the .zip build went fine (by which I mean I found and fixed some bugs). Going to merge now ahead of the release, but happy to keep evolving things.

@dabreegster dabreegster merged commit ca4ddeb into master Sep 18, 2021
@michaelkirk
Copy link
Collaborator

#715 has the motivation

That's a long thread, so I might have missed it, but I couldn't find the part that was relevant to this CLI refactor - is that the right issue number? Or can you link to the conversation in question?

@dabreegster
Copy link
Collaborator Author

I meant #745, whoops, got the number totally wrong

Copy link
Collaborator

@michaelkirk michaelkirk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really great. I'm personally most excited about the discoverability of the commands and their parameters:

$ target/debug/cli
abcli 0.1.0
The A/B Street multi-tool

USAGE:
    cli <SUBCOMMAND>

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

SUBCOMMANDS:
    augment-scenario       Modifies the schedule of every person in an existing scenario
    clip-osm               Clips an OSM file to a boundary. This is a simple Rust port of `osmconvert large_map.osm
                           -B=clipping.poly --complete-ways -o=smaller_map.osm`
    dump-json              Print a binary map or scenario file as JSON
    generate-houses        Procedurally generates houses along empty residential roads of a map
    geo-json-to-osmosis    Reads a GeoJSON file, extracts a polygon from every feature, and writes numbered files in
                           the https://wiki.openstreetmap.org/wiki/Osmosis/Polygon_Filter_File_Format format as
                           output
    help                   Prints this message or the help of the given subcommand(s)
    import                 Runs the main A/B Street importer, which manages maps and scenarios for many cities
    import-grid2-demand    Import a scenario from https:/asu-trans-ai-lab/grid2demand
    import-json-map        Transform a JSON map that's been manually edited into the binary format suitable for
                           simulation
    import-scenario        Import a JSON scenario in the https://a-b-
                           street.github.io/docs/tech/dev/formats/scenarios.html format
    minify-map             Removes nonessential parts of a Map, for the bike network tool
    one-step-import        Imports a one-shot A/B Street map in a single command
    pick-geofabrik         Prints the osm.pbf file from download.geofabrik.de that covers a given boundary
    random-scenario        Generates a random scenario using the proletariat robot travel demand model
$ target/debug/cli dump-json   
error: The following required arguments were not provided:
    <path>

USAGE:
    cli dump-json <path>

For more information try --help
$ target/debug/cli dump-json --help
cli-dump-json 0.1.0
Print a binary map or scenario file as JSON

USAGE:
    cli dump-json <path>

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

ARGS:
    <path>   

One note, cli is kind of a rough name and likely to conflict. Maybe renaming it to abs or abscli would help? But it's not a deal breaker.


use geom::LonLat;

pub fn run(path: String) -> Result<()> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small nit/reminder: Path/PathBuffer are nice and should probably be preferred for this kind of thing... though maybe this method has sufficient interop to make that an undesirably cascading change.

@@ -1,17 +0,0 @@
#!/bin/bash
# This downloads all the cities from https://download.bbbike.org/osm/bbbike/
# and tries to convert them. Don't eat bbike's bandwidth, please.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did bbike.sh and mass_import.sh just go away? Old unused code?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, these were from https:/a-b-street/docs/blob/ecce62e8bd59439d2d01e799e1dcba39418e71e6/book/src/tech/dev/mass_import.md, when I was trying to import a bunch of city centers for a demo to the OSM community. The scripts stopped working a while ago, and I don't have plans to attempt something like this again, so cleanup time

@@ -0,0 +1,261 @@
//! A collection of tools, mostly related to importing maps and scenarios. These are bundled as a
//! single executable to reduce the cost of static linking in the release's file size.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ya know, I didn't really think about the binary size implications. But that makes sense. 👍

@dabreegster
Copy link
Collaborator Author

One note, cli is kind of a rough name and likely to conflict. Maybe renaming it to abs or abscli would help?

Added a TODO. This is a case when I sort of miss the org.abstreet.blah naming scheme from the JVM world. abst becomes a sort of prefix to lots of stuff.

Path/PathBuffer are nice and should probably be preferred for this kind of thing

Added to the TODO in #745. I think this one would be great to do, but it's a large refactoring project. To do it properly, lots of abstio things need to change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants