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

feat: Add support for different output formats on project view and project variables view command #328

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

harrisonmeister
Copy link

@harrisonmeister harrisonmeister commented Feb 13, 2024

Added support for basic, json and table formats for the following octopus commands:

  • project view
  • project variable view

Partially fixes #312 (for project view

Before project view:

octopus project view "A project"             
A project (a-project)
Version control branch: Not version controlled
A sample project description
View this project in Octopus Deploy: https://your.octopus.app/app#/Spaces-1/projects/Projects-4021

After project view:

BASIC format

octopus project view "A project" -f basic
Name: A project (a-project)
Description: A sample project description
Is version controlled: false
Branch: N/A
View this project in Octopus Deploy: https://your.octopus.app/app#/Spaces-1/projects/Projects-4021

TABLE format:

octopus project view "A project" -f table     
KEY                  VALUE
Name                 A project
Slug                 a-project
Description          A sample project description
IsVersionControlled  false
Branch               N/A
Url                  https://your.octopus.app/app#/Spaces-1/projects/Projects-4021

JSON format:

octopus project view "A project" -f json   
{
  "name": "A project",
  "slug": "a-project",
  "description": "sample project description",
  "isversioncontrolled": false,
  "branch": "N/A",
  "url": "https://your.octopus.app/app#/Spaces-1/projects/Projects-4021"
}

Note: this PR does change the output to be in table view if no format is specified for project view. This seems logical given the default output format is table anyway.

Before project variable view:

octopus project variable view "myvariable" --project "A project"
myvariable

Id                 5c931f22-3fc0-f22e-9bac-8b5771a255c4
Value              dev
Description        No description provided
Environment scope  Development

Id                 b36974f9-0f7a-8ad3-2f6e-65ace11bacb0
Value              test
Description        No description provided
Environment scope  Test, Staging

Id             9b90f5d3-f498-be81-491d-1efa62c1ed2b
Value          machine
Description    No description provided
Machine scope  build01

Id             5bed199f-e1da-6f2f-b43c-40d7751c69c9
Value          def-channel
Description    No description provided
Channel scope  Default

Id                  84db4e15-ddf4-d38b-a716-0268cfc951e3
Value               prompted
Description         mydesc
Prompted            true
Prompt Label        mylabel
Prompt Description  mylabeldesc
Prompt Required     false

After project variable view:

BASIC and TABLE format: No change

JSON format:

octopus project variable view "myvariable" --project "A project" -f json
[
  {
    "id": "5c931f22-3fc0-f22e-9bac-8b5771a255c4",
    "value": "dev",
    "description": "",
    "environmentscope": [
      {
        "id": "Environments-1",
        "name": "Development"
      }
    ],
    "rolescope": null,
    "machinescope": null,
    "processscope": null,
    "stepscope": null,
    "channelscope": null
  },
  {
    "id": "b36974f9-0f7a-8ad3-2f6e-65ace11bacb0",
    "value": "test",
    "description": "",
    "environmentscope": [
      {
        "id": "Environments-2",
        "name": "Test"
      },
      {
        "id": "Environments-403",
        "name": "Staging"
      }
    ],
    "rolescope": null,
    "machinescope": null,
    "processscope": null,
    "stepscope": null,
    "channelscope": null
  },
  {
    "id": "9b90f5d3-f498-be81-491d-1efa62c1ed2b",
    "value": "machine",
    "description": "",
    "environmentscope": null,
    "rolescope": null,
    "machinescope": [
      {
        "id": "Machines-962",
        "name": "build01"
      }
    ],
    "processscope": null,
    "stepscope": null,
    "channelscope": null
  },
  {
    "id": "5bed199f-e1da-6f2f-b43c-40d7751c69c9",
    "value": "def-channel",
    "description": "",
    "environmentscope": null,
    "rolescope": null,
    "machinescope": null,
    "processscope": null,
    "stepscope": null,
    "channelscope": [
      {
        "id": "Channels-4161",
        "name": "Default"
      }
    ]
  },
  {
    "id": "84db4e15-ddf4-d38b-a716-0268cfc951e3",
    "value": "prompted",
    "description": "mydesc",
    "environmentscope": null,
    "rolescope": null,
    "machinescope": null,
    "processscope": null,
    "stepscope": null,
    "channelscope": null,
    "prompted": true,
    "promptlabel": "mylabel",
    "promptlabeldescription": "mylabeldesc",
    "promptrequired": "false"
  }
]

@harrisonmeister
Copy link
Author

Linked with #318 which looks to fix project-group view

@harrisonmeister harrisonmeister marked this pull request as ready for review February 14, 2024 11:19
@harrisonmeister harrisonmeister changed the title Add support for all output formats on project view command Add support for different output formats on project view and project variables view command Feb 14, 2024
Copy link

@tleed5 tleed5 left a comment

Choose a reason for hiding this comment

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

Looks good to me, I tested it locally and all is working well. Just one question but nothing blocking.

Also you might need to squash and merge this PR and include a conventional commit on the merge commit so we get a release note generated for this change

case constants.OutputFormatBasic, constants.OutputFormatTable:
fmt.Fprintln(out, output.Bold(filteredVars[0].Name))
for _, v := range filteredVars {
data := []*output.DataRow{}

Copy link

Choose a reason for hiding this comment

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

Should this also print out the KEY VALUE heading like the project view does?

Suggested change
data = append(data, output.NewDataRow(output.Bold("KEY"), output.Bold("VALUE")))

Copy link
Author

Choose a reason for hiding this comment

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

Not against that change - although it perhaps should only apply to the table format (as it is with project view) ?

Copy link

Choose a reason for hiding this comment

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

Yeah definitely, it would probably be a bit confusing in the basic format

Copy link
Author

Choose a reason for hiding this comment

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

I've made a change in 98078bf but wanted to mention that Ben P mentioned he was going to review the view command output format holistically. See this thread (internal link) for more details.

@APErebus APErebus changed the title Add support for different output formats on project view and project variables view command feat: Add support for different output formats on project view and project variables view command Sep 13, 2024
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.

project view, project-group view commands don't respect --output-format switch
2 participants