X Tutup
Skip to content

Add export functionality to codespace commands#4591

Merged
mislav merged 4 commits intotrunkfrom
codespaces-json-export
Oct 25, 2021
Merged

Add export functionality to codespace commands#4591
mislav merged 4 commits intotrunkfrom
codespaces-json-export

Conversation

@mislav
Copy link
Copy Markdown
Contributor

@mislav mislav commented Oct 22, 2021

This adds --json and --template export functionality to gh cs list and gh cs ports.

Additionally, it switches gh cs ports table output to gh's own TablePrinter instead of the tablewriter package.

Finally, this was able to remove the obsolete codespaces/output package.

Followup to #4516

@mislav mislav requested review from a team as code owners October 22, 2021 12:22
@mislav mislav requested review from samcoe and removed request for a team October 22, 2021 12:22
"lastUsedAt",
}

func (c *Codespace) ExportData(fields []string) *map[string]interface{} {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A Go map value is a reference to a hash table, so you almost never need *map types.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ah good to know! I will address this across all commands in a followup PR.

HostPublicKeys []string `json:"hostPublicKeys"`
}

var CodespaceFields = []string{
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All exported declarations should have a doc comment.

"github.com/cli/cli/v2/pkg/cmd/codespace/output"
"github.com/cli/cli/v2/pkg/cmdutil"
"github.com/cli/cli/v2/pkg/liveshare"
"github.com/cli/cli/v2/utils"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

import cliutils "github.com/cli/cli/v2/utils"

Generally, you should never name a package "util".

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agreed. We've already marked the utils package as "deprecated", meaning that it's pending removal; we just have to extract the still-useful parts of it (table writer, relative time helpers) into their own packages.

case "label":
data[f] = pi.Label()
case "browseUrl":
data[f] = pi.BrowseURL()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

default: log.Fatal?

"hasUncommitedChanges": c.GitStatus.HasUncommitedChanges,
}
default:
sf := v.FieldByNameFunc(func(s string) bool {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What happens when f is misspelled? I suspect the map has an (f, nil) entry. It would be better to log.Fatal.

This comment was marked as spam.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It panics, but the user is not able to pass in misspelled fields because the list of requested fields is always checked against a list of allowed fields.

@CamiloGarciaLaRotta
Copy link
Copy Markdown
Contributor

🙂 loving the new functionality. No opinions on the codebase, but curious if we need additional test

Copy link
Copy Markdown
Contributor

@vilmibm vilmibm left a comment

Choose a reason for hiding this comment

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

looking much better ✨

@mislav mislav merged commit 8d9e8e3 into trunk Oct 25, 2021
@mislav mislav deleted the codespaces-json-export branch October 25, 2021 15:10
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.

6 participants

X Tutup