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

Creating state module for goquery shell state (print mode, debug, etc) and implement print lines #42

Merged
merged 1 commit into from
Oct 7, 2019

Conversation

AbGuthrie
Copy link
Owner

  • Created printmode enums and printer.go
  • printer.go now has two different print functions (implemented lines)
  • Created new command .mode which takes and sets current print mode for the util print switch statement
  • Normalized some function names (lowercase since not public to other modules)

Closes #41 and update #11 (print lines)

image

Created printmode enums and printer.go
printer.go now has two different print functions (implemented lines)

Created new command .mode which takes and sets current print mode for the util print switch statement

Normalized some function names (lowercase since not public to other modules)
@AbGuthrie AbGuthrie added new command For issues or PRs that add new commands to goquery UX For things relating to the experience of someone using goquery labels Oct 5, 2019
Copy link
Collaborator

@obelisk obelisk left a comment

Choose a reason for hiding this comment

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

My only real comment is to change the help output to line instead of lines. Otherwise it looks perfect to land.

".exit": exit,
"ls": ListDirectory,
"cd": ChangeDirectory,
"ls": listDirectory,
Copy link
Collaborator

Choose a reason for hiding this comment

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

My bad

}
SuggestionsMap = []prompt.Suggest{
{".connect", "Connect to a host with UUID"},
{".disconnect", "Disconnect from a host with UUID"},
{".query", "Schedule a query on a host"},
{".mode", "Change print mode (json, lines, etc)"},
Copy link
Collaborator

Choose a reason for hiding this comment

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

line

"github.com/AbGuthrie/goquery/config"
)

var validModes = map[string]config.PrintMode{
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

}

config.SetPrintMode(mode)
fmt.Printf("Print mode set to '%s'.\n", modeArg)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would mark this as debug output to more closely mirror this osqueryi implementation.

Copy link
Collaborator

Choose a reason for hiding this comment

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

In that we should change it to debug output when that is implemented

@@ -0,0 +1,41 @@
// Package config is repsonsible for setting and returning the current
// state of the shell in regards to configuration flags and mode options
package config
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should the current host be stored in here?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe not now but in the future

}
// To center align keys with "=" get longest length key name
keyPadding := 0
for key := range results[0] {
Copy link
Collaborator

Choose a reason for hiding this comment

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

OOC does go have native implementations of higher order functions? This would make a good fold.

case 0:
// PrettyPrintQueryResults prints a given []result map set to standard out
// taking into consideration the current state.go's print mode
func PrettyPrintQueryResults(results []map[string]string) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should typedef []map[string]string to Rows if possible. Can go do that?


// PrintMode constants enum
const (
PrintJSON PrintMode = 0
Copy link
Collaborator

Choose a reason for hiding this comment

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

In go do constants need to be specified or will they auto assign if left out (which we should do if go supports)

@AbGuthrie AbGuthrie merged commit f4a8453 into master Oct 7, 2019
@AbGuthrie AbGuthrie deleted the printmodes branch May 20, 2020 08:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new command For issues or PRs that add new commands to goquery UX For things relating to the experience of someone using goquery
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create a config module to hold goquery configurations state
2 participants