oci-cli
oci-cli copied to clipboard
ENH: Add `--output tsv` along with `table` and `json` options for tab-separated report output
I can't tell you how many times a day I do this:
oci iam compartment list --compartment-id-in-subtree true \
--query 'data[*].join(`\t`, [name, "lifecycle-state"]) | join(`\n`, @)' \
--raw-output
…In order to produce tab-separated report I can capture then paste to Excel, etc. (or format further by piping to column
command or similar) please add an additional --output tsv
option that would format the output similar to --output table
but without the box lines and separating each column in the header and body by tab ASCII 9 symbols?
oci iam compartment list --compartment-id-in-subtree true \
--query 'data[*].[name, "lifecycle-state"]' \
--output tsv
Column1 Column2
sandbox ACTIVE
prod ACTIVE
nonprod ACTIVE
prod.biZVAxli DELETED
Hi, The simple way is to create python script list_compartment.py with below code and execute using pytnon3 list_compartment.py
import oci
config = oci.config.from_file(oci.config.DEFAULT_LOCATION, oci.config.DEFAULT_PROFILE)
identity_client = oci.identity.IdentityClient(config)
tenant_id = config['tenancy']
compartments = oci.pagination.list_call_get_all_results(
identity_client.list_compartments,
compartment_id=tenant_id,
compartment_id_in_subtree=True).data
for c in compartments:
print(f"{c.name}\t{c.lifecycle_state}")
Thanks Jon, for the suggestion. We will plan this enhancement request.
@jeliker Check out https://github.com/oracle/oci-cli/blob/master/scripts/examples/project_o/README.md
Project "o" provides several output options, one of which is tsv.
To do what you want, install "o". Then run:
$ o -o 'name lifecycle' list compart -ciis true -all .
oci iam compartment list \
--compartment-id-in-subtree true \
--all
outpost ACTIVE
sandbox1 ACTIVE
workload.spbAEuEo DELETED
workshop ACTIVE
Note: there's a "tab" character in between name and lifecycle in the command.
o will convert the above command into a complete oci command, select output based on "-o fields", and format results into tsv. All from that brief little command.
I've never used tsv but figured someone would want it one day!
My everyday format is the default table out - without the ascii decorations.
$ o -qo name#state list compart -ciis true -all .
name lifecycle-state
outpost ACTIVE
sandbox1 ACTIVE
workload.spbAEuEo DELETED
workshop ACTIVE
Default "o" output is meant to be useful for humans.
Jon can you try project o where this is possible?
Thank you for the work-around suggestion but, as described, I have a work-around now that doesn't require additional tools installed. In my scenarios it is not often feasible to install additional software so still hoping for a native solution.
Note I could have always opted to use another tool whether the o
script or jq
or others. My suggestion is for improvement in this tool itself.
Understood and thanks for the suggestion Jon-Eric. We will consider this enhancement.