refactor: Make CLI commands consistent #163
Conversation
* Move individual "entity" and "entities" commands into "entity info" and "entity list" commands.
Codecov Report
@@ Coverage Diff @@
## main #163 +/- ##
==========================================
+ Coverage 42.06% 45.47% +3.41%
==========================================
Files 68 74 +6
Lines 6652 6793 +141
==========================================
+ Hits 2798 3089 +291
+ Misses 3854 3704 -150
Continue to review full report at Codecov.
|
* No longer duplicate arguments and options * Just "generate" the command functions multiple times and place it under different Click groups. * Avoid circular imports by making client.cli.main as a module when doing so.
* All GraphQL/output fields are now defined as FieldSpec. * All CLI/functional API implementations refer the central FieldSet defined in the `ai.backend.client.output.fields` module. * All FieldSpec instances have their own formatters.
…esource_slot_formatter
…esource_slot_formatter
…okchalatte/backend.ai-client-py into feature/revamp-cli-consistency
* Use Rich to pretty-format the announcements in CLI
Chrysan Angela Piarso seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
The CLA check failure is due to a misconfiguraion of git client: |
* Create and apply `sizebytes_output_formatter`
* refactor: Make all cli.admin module names singular * refactor: Reorganize admin command hierarchy - Move individual "entity" and "entities" commands into "entity info" and "entity list" commands. - No longer duplicate arguments and options - Just "generate" the command functions multiple times and place it under different Click groups. - Avoid circular imports by making client.cli.main as a module when doing so. * wip: Add `client.cli.output` subpkg to provide common interface for output - All GraphQL/output fields are now defined as FieldSpec. - All CLI/functional API implementations refer the central FieldSet defined in the `ai.backend.client.output.fields` module. - All FieldSpec instances have their own formatters. * setup: Update backend.ai-cli * fix: remove support for servers with API ver older than v5.20191215 * maintenance: Remove Python 3.7 support and now require 3.8 or later. * fix: Improve handling of JSON-string CLI args better * Overrided the CLA check due to git client misconfiguration to specify author emails Co-authored-by: Chrysan Angela Piarso <chrysan@lablup.com>
Let's make command arguments and options to be consistent and update to Click 8.0.x.
The client SDK consists of: low-level API (auth, request) + functional API (wrappers around REST and GraphQL) + CLI commands. This PR will rewrite the CLI commands, and this will not be backward compatible due to ambiguity of command parsing. (Just imagine that
etcdctl
requiresETCDCTL_API
environment variable to switch between v2 and v3 command sets.)What's included in this PR:
backend.ai admin? <entity> {info,list,...}
. e.g.,backend.ai admin agents
backend.ai admin agent i-dgx001
(😞 mix of plural and singular "agent" and "agents")backend.ai admin scaling-group -n default
(😞 some individual item query commands just accept an argument but some accept an arbitrarily named option -- inconsistent!!)backend.ai admin agent list
backend.ai admin agent info i-dgx001
(💯 now consistent singular name followed bylist
,info
)backend.ai admin scaling-group info default
(💯 now consistently accept the key as a sole argument)run
,ps
,rm
, etc., but they are now the pure duplicate, by generating the command handler function twice for different command groups and thus removing potential of missing new options/arguments due to manual copy-and-paste of codes.--output=console
(the default) or--output=json
option to control the output format of CLIlist
andinfo
commands. e.g.,backend.ai --output=json ps --dead
backend.ai --output=json admin agent list
ai.backend.client.output
subpackage.FieldSpec
asfields
arguments, instead of a list ofstr
.FieldSpec
instances fromai.backend.client.output.fields
and each functional API module's_default_list_fields
and_default_detail_fields
variables.jq
command and shell scripts.--limit
and--offset
to control pagination of paginated list commands (NOTE: Not alllist
commands support this...)backend.ai ps --dead --offset=30 --limit=20
count
(the number of items in the current page result),total_count
(the number of all items in the server),items
(the list of item objects) fields so that client may perform its own pagination as needed, in a consistent way.Left as future work:
--output=json
support for mutation and session execution commands. They currently work like before, just printing out console messages regardless of the output option.