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

Support CSV output, error handling #42

Closed
wants to merge 2 commits into from
Closed

Support CSV output, error handling #42

wants to merge 2 commits into from

Conversation

pcarrier
Copy link
Owner

CSV output as suggested in #34.

gauth.go Show resolved Hide resolved
gauth.go Outdated
cfgPath := os.Getenv("GAUTH_CONFIG")
if cfgPath == "" {
user, err := user.Current()
usr, err := user.Current()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just a minor cosmetic thing: If you're going to bother abbreviating anyway, might as well just use u. It doesn't escape this scope anyway.

gauth.go Outdated
cw := csv.NewWriter(os.Stdout)
for _, record := range cfg {
name, secret := record[0], record[1]
_, curr, next, err := gauth.Codes(secret, currentTS)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there some reason to omit the previous code in the CSV output? If the goal is to make the output of the tool machine-readable, I'd suggest it should contain the same information as the human-readable version.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Included.

gauth.go Outdated
@@ -17,13 +19,16 @@ import (
)

func main() {
useCSV := flag.Bool("csv", false, "Output CSV for easy machine processing")
Copy link
Collaborator

Choose a reason for hiding this comment

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

A minor cosmetic point:

This is functionally correct, but it's fairly conventional to put flag definitions at global scope (done during initialization) so they are visible to the whole main package:

var (
  useCSV = flag.Bool("csv", false, "Output CSV for easy machine processing")
)

func main() {
  flag.Parse()
  // …
}

There's only one right now, and it's only used inside main at the moment, but based on some of the other open issues I predict there will be more flags coming along—and it'd be nice if they could be accessed from other helpers in the main package.

YMMV.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Oh thanks for the reminder, haven't written go or touched that code in a long time, 💯 must fix.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Done.

@pcarrier pcarrier force-pushed the pcarrier/csv branch 3 times, most recently from a43ce65 to ca0967d Compare August 1, 2021 13:53
@pcarrier pcarrier closed this Nov 13, 2023
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.

2 participants