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 --output=json flag to epinio namespace [list|show] #2547

Merged

Conversation

enrichman
Copy link
Member

@enrichman enrichman commented Sep 4, 2023

This PR adds the support for the JSON output in the namespace list and namespace show commands.

When selected it will silence the warning version, and it will still output a user-readable error in case of failure. The exit code will be a non-zero though. Not sure if we should provide a JSON error as well instead of a plain text.

-> % epinio namespace show workspace --output json | jq
{
  "meta": {
    "name": "workspace",
    "createdAt": "2023-09-04T13:04:52Z"
  },
  "apps": [
    "sample"
  ]
}

It also adds an enumValue flag that can be used to provide a flag with a fixed set of values, and its completion func.

@enrichman enrichman requested a review from a team as a code owner September 4, 2023 16:19
@enrichman enrichman linked an issue Sep 4, 2023 that may be closed by this pull request
@enrichman enrichman self-assigned this Sep 4, 2023
@enrichman enrichman added the kind/enhancement New feature or request label Sep 4, 2023
@enrichman enrichman added this to the v1.10.0 milestone Sep 4, 2023
@codecov
Copy link

codecov bot commented Sep 4, 2023

Codecov Report

Patch coverage is 70.68% of modified lines.

Files Changed Coverage
internal/cli/commons.go 11.11%
internal/cli/termui/ui.go 70.00%
internal/cli/enum_flag.go 71.42%
internal/cli/namespaces.go 100.00%
internal/cli/root.go 100.00%
internal/cli/usercmd/namespace.go 100.00%

📢 Thoughts on this report? Let us know!.

@gitricko
Copy link

gitricko commented Sep 4, 2023

Great!

@mmartin24
Copy link
Contributor

Tested in branch and seems to be ok:

  • Check default without flag outputs to text:
➜  epinio git:(2527-add-output-json-flag-to-epinio-namespace-command) ✗ epinio namespace show workspace   

🚢  Showing namespace...
Name: workspace

✔️  Details:
|      KEY       |                VALUE                |
|----------------|-------------------------------------|
| Name           | workspace                           |
| Created        | 2023-09-05 15:43:02 +0200 CEST      |
| Applications   | testapp-cli                         |
| Configurations | xcfefa578ebf738cc24fe12a0f5a3-mysql |

  • Checked -o json correctly outputs to json format:
➜  epinio git:(2527-add-output-json-flag-to-epinio-namespace-command) ✗ epinio namespace show workspace -o json | jq
{
  "meta": {
    "name": "workspace",
    "createdAt": "2023-09-05T13:43:02Z"
  },
  "apps": [
    "testapp-cli"
  ],
  "configurations": [
    "xcfefa578ebf738cc24fe12a0f5a3-mysql"
  ]
  • Checked both flags -o, --output work
  • Checked worked with epinio namespace list;
➜  epinio git:(2527-add-output-json-flag-to-epinio-namespace-command) ✗ epinio namespace list workspace -o json | jq
[
  {
    "meta": {
      "name": "ns-1",
      "createdAt": "2023-09-05T14:00:35Z"
    }
  },
  {
    "meta": {
      "name": "workspace",
      "createdAt": "2023-09-05T13:43:02Z"
    },
    "apps": [
      "testapp-cli"
    ],
    "configurations": [
      "xcfefa578ebf738cc24fe12a0f5a3-mysql"
    ]
  }
]

@enrichman, the only thing I noted was a time difference between text and json output due to its format:

image

I am not sure if we want to do something about it or assume this output difference as ok.

@enrichman
Copy link
Member Author

@mmartin24 I would say that is OK. As a user I'm expecting the text format to be easy to ready and so the local timezone formatting is expected.

@enrichman enrichman merged commit 60affe8 into main Sep 6, 2023
18 checks passed
@enrichman enrichman deleted the 2527-add-output-json-flag-to-epinio-namespace-command branch September 6, 2023 14:27
@mmartin24
Copy link
Contributor

Rechecked in Epinio Server Version: v1.10.0-rc2

  • Checked epinio namespace list -o json
➜  epinio git:(main) ✗ epinio namespace list -o json  | jq
[
  {
    "meta": {
      "name": "ns-1",
      "createdAt": "2023-09-20T13:21:36Z"
    }
  },
  {
    "meta": {
      "name": "workspace",
      "createdAt": "2023-09-20T11:59:06Z"
    },
    "configurations": [
      "config-1",
      "xcfefa578ebf738cc24fe12a0f5a3-mysql"
    ]
  }
]
  • Checked epinio namespace show workspace -o json
➜  epinio git:(main) ✗ epinio namespace show workspace -o json  | jq
{
  "meta": {
    "name": "workspace",
    "createdAt": "2023-09-20T11:59:06Z"
  },
  "configurations": [
    "config-1",
    "xcfefa578ebf738cc24fe12a0f5a3-mysql"
  ]
}

@mmartin24
Copy link
Contributor

Sanity check on 1.10.0:

  epinio git:(main) epinio namespace list -o json  | jq                                               
[
  {
    "meta": {
      "name": "workspace",
      "createdAt": "2023-09-25T10:06:13Z"
    }
  }
]
➜  epinio git:(main) epinio info                        

✔️  Epinio Environment
Platform: k3s
Kubernetes Version: v1.25.4+k3s1
Epinio Server Version: v1.10.0
Epinio Client Version: v1.10.0

@enrichman enrichman changed the title Add --output flag with JSON support for Epinio namespace list and show commands Added --output=json flag to epinio namespace [list|show] Sep 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/enhancement New feature or request
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Add --output json flag to epinio namespace command
4 participants