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

Added foundation of command line interface argument/flag parsing/handling #6

Merged
merged 1 commit into from Apr 1, 2022

Conversation

jhodapp
Copy link
Contributor

@jhodapp jhodapp commented Mar 31, 2022

Added the use of the crate clap for command line interface argument/flag parsing.

Clap reference

Provides -d|--debug, -V|--version and -h|--help with this changeset.

Refer to the ambi_mock_client CLI design document for more background info.

Also sets the foundation for separation of application logic now being in lib.rs instead of everything being in main.rs. See the Rust book section 12.3 for more info.

Example output

$ ambi_mock_client --help
Ambi Mock Client 0.1.0
Rust Never Sleeps community (https://github.com/Jim-Hodapp-Coaching/)
This application emulates a real set of hardware sensors that can report on environmental conditions
such as temperature, pressure, humidity, etc.

USAGE:
    ambi_mock_client [OPTIONS]

OPTIONS:
    -d, --debug
            Turns verbose console debug output on

    -h, --help
            Print help information

    -V, --version
            Print version information

or setting verbose debug output on:

$ ambi_mock_client -d
Debug mode is now *on*

cli: Cli { debug: true }

Sending POST request to http://localhost:4000/api/readings/add as JSON: {"temperature":"24.2","humidity":"70.1","pressure":"960","dust_concentration":"999","air_purity":"High Pollution"}
Response: Ok(
    Response {
        url: Url {
            scheme: "http",
            cannot_be_a_base: false,
            username: "",
            password: None,
            host: Some(
                Domain(
                    "localhost",
                ),
            ),
            port: Some(
                4000,
            ),
            path: "/api/readings/add",
            query: None,
            fragment: None,
        },
        status: 200,
        headers: {
            "cache-control": "max-age=0, private, must-revalidate",
            "content-length": "60",
            "content-type": "application/json; charset=utf-8",
            "date": "Thu, 31 Mar 2022 20:17:33 GMT",
            "server": "Cowboy",
            "x-request-id": "FuF_EewOgIHT5BkAAEfn",
        },
    },
)

Closes #5

…arsing. Provides -d, -V and -h with this commit.
@jhodapp jhodapp added the enhancement New feature or request label Mar 31, 2022
@jhodapp jhodapp self-assigned this Mar 31, 2022
Copy link

@glynos glynos left a comment

Choose a reason for hiding this comment

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

Clap looks like an interesting utility! LGTM

@jhodapp
Copy link
Contributor Author

jhodapp commented Apr 1, 2022

Clap looks like an interesting utility! LGTM

Indeed, I was pleasantly surprised to find this while searching around. I started down the path of the Rust Book's CLI handling but then stumbled upon clap. I'm very impressed with its developer interface.

@jhodapp
Copy link
Contributor Author

jhodapp commented Apr 1, 2022

@calebbourg thanks for the review!

@jhodapp jhodapp merged commit 328af96 into master Apr 1, 2022
@jhodapp jhodapp deleted the basic_command_line_interface branch April 1, 2022 22:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Add basic command line interface to ambi_mock_client
3 participants