Skip to content

Add pets-cli example CLI program - #27

Merged
rickwporter merged 1 commit into
mainfrom
rickwporter/pets-cli
Nov 5, 2026
Merged

rickwporter merged 1 commit into
mainfrom
rickwporter/pets-cli

Conversation

@rickwporter

Copy link
Copy Markdown
Owner

RATIONALE

Add a simple CLI which uses prettytable for rendering REST responses. The pets-cli is an implementation based on the included OpenAPI specification.

CHANGES

Added examples/pets-cli as a fully worked example.

EXAMPLE

Below are examples of using the program. In this case, the API_HOST and API_KEY are set in the environment, so not needed as parameter:

rick@Ricks-MacBook-Pro pets-cli % java -jar target/pets.jar                                                         
Usage: pets [-hV] [-f=<format>] [-k=<apiKey>] [-s=<server>] [COMMAND]
Manage pets and print the response with prettytable.
  -f, --format=<format>    Format: TEXT, RICH, CSV, HTML, JSON. OUTPUT_FORMAT is the default (default: RICH)
  -h, --help               Show this help message and exit.
  -k, --api-key=<apiKey>   Bearer token from API_KEY. Omitted when both are empty.
  -s, --server=<server>    Petstore base URL. Uses API_HOST when omitted (default: http://127.0.0.1:8080)
  -V, --version            Print version information and exit.
Commands:
  list    List all pets. The server pages with limit and the x-next header.
  add     Create a pet.
  show    Info for a specific pet.
  delete  Delete a pet.
Examples:
  pets list --limit 5
  pets show 1
  pets add --id 7 --name Fido --owner Rick --tag trained
  pets delete 1
rick@Ricks-MacBook-Pro pets-cli % java -jar target/pets.jar list
┏━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┓
┃ Name     ┃ Properties         ┃
┡━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━┩
│ Spot     │  id     1          │
│          │  tag    None       │
│          │  owner  Firehouse  │
├──────────┼────────────────────┤
│ Clifford │  id     2          │
│          │  tag    big        │
│          │  owner  Emily      │
├──────────┼────────────────────┤
│ Lassie   │  id     3          │
│          │  tag    None       │
│          │  owner  Tommy      │
└──────────┴────────────────────┘
Found 3 items
rick@Ricks-MacBook-Pro pets-cli % java -jar target/pets.jar show 2
┏━━━━━━━━━━┳━━━━━━━━━━┓
┃ Property ┃ Value    ┃
┡━━━━━━━━━━╇━━━━━━━━━━┩
│ id       │ 2        │
│ name     │ Clifford │
│ tag      │ big      │
│ owner    │ Emily    │
└──────────┴──────────┘
rick@Ricks-MacBook-Pro pets-cli % java -jar target/pets.jar delete 1
Empty response.
rick@Ricks-MacBook-Pro pets-cli % java -jar target/pets.jar list    
┏━━━━━━━━━━┳━━━━━━━━━━━━━━━━┓
┃ Name     ┃ Properties     ┃
┡━━━━━━━━━━╇━━━━━━━━━━━━━━━━┩
│ Clifford │  id     2      │
│          │  tag    big    │
│          │  owner  Emily  │
├──────────┼────────────────┤
│ Lassie   │  id     3      │
│          │  tag    None   │
│          │  owner  Tommy  │
└──────────┴────────────────┘
Found 2 items
rick@Ricks-MacBook-Pro pets-cli %

@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

There is no coverage information present for the Files changed

Total Project Coverage 99.91% 🍏

@rickwporter
rickwporter merged commit f85226f into main Nov 5, 2026
4 checks passed
@rickwporter
rickwporter deleted the rickwporter/pets-cli branch November 5, 2026 15:51
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.

1 participant