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

ENH: Add --output tsv along with table and json options for tab-separated report output #754

Open
jeliker opened this issue Mar 7, 2024 · 6 comments
Labels
SDK Issue pertains to the SDK itself and not specific to any service

Comments

@jeliker
Copy link

jeliker commented Mar 7, 2024

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
@adizohar
Copy link
Member

adizohar commented Mar 8, 2024

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}")

@karthik-k-kamath karthik-k-kamath added the SDK Issue pertains to the SDK itself and not specific to any service label Mar 8, 2024
@karthik-k-kamath
Copy link
Member

Thanks Jon, for the suggestion.
We will plan this enhancement request.

@kevco-us
Copy link
Member

@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.

@karthik-k-kamath
Copy link
Member

Jon can you try project o where this is possible?

@jeliker
Copy link
Author

jeliker commented Mar 22, 2024

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.

@karthik-k-kamath
Copy link
Member

Understood and thanks for the suggestion Jon-Eric. We will consider this enhancement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
SDK Issue pertains to the SDK itself and not specific to any service
Projects
None yet
Development

No branches or pull requests

4 participants