Skip to content

Conversation

@mdelapenya
Copy link
Contributor

@mdelapenya mdelapenya commented Oct 6, 2021

What does this PR do?

It exposes a new flag to set the format when listing existing profiles. The supported formats are table and json, being table the default one.

$ go run main.go profiles list --help
2021/10/06 06:14:55  WARN CommitHash is undefined, in both /Users/mdelapenya/.elastic-package/version and the compiled binary, config may be out of date.
List available profiles

Usage:
  elastic-package profiles list [flags]

Flags:
      --format string   format of the profiles list (table | json) (default "table")
  -h, --help            help for list

Global Flags:
  -v, --verbose   verbose mode

Why is it important?

We'd like the tool to provide the existing profiles in a machine-readable format, as we want to check if there is a profile. Yes, we could directly check the filesystem, but this is more consistent :)

How to test this locally

Run the tool in table format:

$ go run main.go profiles list
2021/10/06 06:07:47  WARN CommitHash is undefined, in both /Users/mdelapenya/.elastic-package/version and the compiled binary, config may be out of date.
+------------------------------+---------------------------+------------+-----------+--------------------------------------------------------------------------+
|             NAME             |       DATE CREATED        |    USER    |  VERSION  |                                   PATH                                   |
+------------------------------+---------------------------+------------+-----------+--------------------------------------------------------------------------+
| custom-pr                    | 2021-10-04T18:02:48+02:00 | mdelapenya | 1af18c9   | /Users/mdelapenya/.elastic-package/profiles/custom-pr                    |
+------------------------------+---------------------------+------------+-----------+--------------------------------------------------------------------------+
| default                      | 2021-10-06T06:01:26+02:00 | mdelapenya | undefined | /Users/mdelapenya/.elastic-package/profiles/default                      |
+------------------------------+---------------------------+------------+-----------+--------------------------------------------------------------------------+
| default_1af18c9_1629958780   | 2021-08-26T08:19:40+02:00 | mdelapenya | 1af18c9   | /Users/mdelapenya/.elastic-package/profiles/default_1af18c9_1629958780   |
+------------------------------+---------------------------+------------+-----------+--------------------------------------------------------------------------+
| default_undefined_1633422611 | 2021-10-05T10:30:11+02:00 | mdelapenya | undefined | /Users/mdelapenya/.elastic-package/profiles/default_undefined_1633422611 |
+------------------------------+---------------------------+------------+-----------+--------------------------------------------------------------------------+

Run the tool in JSON format:

$ go run main.go profiles list --format json
2021/10/06 06:07:47  WARN CommitHash is undefined, in both /Users/mdelapenya/.elastic-package/version and the compiled binary, config may be out of date.
[{"name":"custom-pr","date_created":"2021-10-04T18:02:48.167182+02:00","user":"mdelapenya","version":"1af18c9","path":"/Users/mdelapenya/.elastic-package/profiles/custom-pr"},{"name":"default","date_created":"2021-10-06T06:01:26.74122+02:00","user":"mdelapenya","version":"undefined","path":"/Users/mdelapenya/.elastic-package/profiles/default"},{"name":"default_1af18c9_1629958780","date_created":"2021-08-26T08:19:40.39341+02:00","user":"mdelapenya","version":"1af18c9","path":"/Users/mdelapenya/.elastic-package/profiles/default_1af18c9_1629958780"},{"name":"default_undefined_1633422611","date_created":"2021-10-05T10:30:11.968095+02:00","user":"mdelapenya","version":"undefined","path":"/Users/mdelapenya/.elastic-package/profiles/default_undefined_1633422611"}]

Run the tool with a non-supported format:

$ go run main.go profiles list --format FOO
2021/10/06 06:12:07  WARN CommitHash is undefined, in both /Users/mdelapenya/.elastic-package/version and the compiled binary, config may be out of date.
Error: format FOO not supported
exit status 1

@mdelapenya mdelapenya self-assigned this Oct 6, 2021
@mdelapenya mdelapenya requested a review from a team October 6, 2021 04:14
@mdelapenya mdelapenya marked this pull request as ready for review October 6, 2021 04:17
@mdelapenya mdelapenya requested review from a team and mtojek and removed request for mtojek October 6, 2021 04:19
@elasticmachine
Copy link
Collaborator

elasticmachine commented Oct 6, 2021

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview preview

Expand to view the summary

Build stats

  • Duration: 21 min 27 sec

🤖 GitHub comments

To re-run your PR in the CI, just comment with:

  • /test : Re-trigger the build.

@mdelapenya mdelapenya requested a review from mtojek October 6, 2021 07:59
Copy link
Contributor

@mtojek mtojek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only few nit-picks, but I suppose you're good to go.

@mdelapenya
Copy link
Contributor Author

Only few nit-picks, but I suppose you're good to go.

Resolved in follow-up commits. Thanks for the review!!

@mdelapenya mdelapenya merged commit c409b5b into elastic:master Oct 6, 2021
@mdelapenya mdelapenya deleted the profiles-json-format branch October 11, 2021 05:45
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.

4 participants