Skip to content

[wip] cli: Add info command#363

Closed
aequitas wants to merge 2 commits intopurpleidea:masterfrom
aequitas:info
Closed

[wip] cli: Add info command#363
aequitas wants to merge 2 commits intopurpleidea:masterfrom
aequitas:info

Conversation

@aequitas
Copy link
Contributor

@aequitas aequitas commented Feb 27, 2018

For now just lists resources and functions, more to be added soon.

$ ./mgmt info funcs -t
answer			answer() int
contains
datetime		datetime() int
datetime_print		datetime_print(int) str
defaultenv		defaultenv(str, str) str
env			env() {str: str}
example_errorbool	example_errorbool(bool) str
exchange		exchange(str, str) {str: str}
flipflop		flipflop() bool
getenv			getenv(str) str
hasenv			hasenv(str) bool
hostname		hostname() str
int2str			int2str(int) str
kvlookup		kvlookup(str) {str: str}
len
load			load() struct{x1 float; x5 float; x15 float}
maplookup
pow			pow(float, float) float
printf
random1			random1(int) str
schedule
structlookup
template
vumeter			vumeter(str, int, float) str
$ ./mgmt info resources
augeas
aws:ec2
exec
file
graph
group
hostname
kv
msg
noop
nspawn
password
pkg
print
svc
test
timer
user
virt

@aequitas
Copy link
Contributor Author

fixes #312

@aequitas aequitas force-pushed the info branch 6 times, most recently from bb91bd3 to 0e96031 Compare February 27, 2018 15:39
@aequitas
Copy link
Contributor Author

aequitas commented Feb 27, 2018

Now also with a little bit of resource types:

./mgmt info r -t
augeas    file (string), lens (string), sets ([]resources.AugeasSet)
aws:ec2   state (string), region (string), type (string), imageid (string), watchendpoint (string), watchlistenaddr (string), erroronmalformedpost (bool), userdata (string), publicipv4 (string), privateipv4 (string), instanceid (string)
exec      cmd (string), shell (string), timeout (int), watchcmd (string), watchshell (string), ifcmd (string), ifshell (string), user (string), group (string), output (*string), stdout (*string), stderr (*string)
file      path (string), dirname (string), basename (string), content (*string), source (string), state (string), owner (string), group (string), mode (string), recurse (bool), force (bool)
graph     graph (*pgraph.Graph)
group     state (string), gid (*uint32)
hostname  hostname (string), prettyhostname (string), statichostname (string), transienthostname (string)
kv        key (string), value (*string), skiplessthan (bool), skipcmpstyle (resources.KVResSkipCmpStyle)
msg       body (string), priority (string), fields (map[string]string), journal (bool), syslog (bool)
noop      comment (string)
nspawn    state (string)
password  length (uint16), saved (bool), checkrecovery (bool), password (*string)
pkg       state (string), allowuntrusted (bool), allownonfree (bool), allowunsupported (bool)
print     msg (string)
svc       state (string), startup (string), session (bool)
timer     interval (uint32)
user      state (string), uid (*uint32), gid (*uint32), group (*string), groups ([]string), homedir (*string), allowduplicateuid (bool)
virt      uri (string), state (string), transient (bool), cpus (uint), maxcpus (uint), memory (uint64), osinit (string), boot ([]string), disk ([]resources.diskDevice), cdrom ([]resources.cdRomDevice), network ([]resources.networkDevice), filesystem ([]resources.filesystemDevice), auth (*resources.VirtAuth), hotcpus (bool), restartondiverge (string), restartonrefresh (bool)

It's ugly atm, eg: no proper indicator for readonly types.

Copy link
Owner

@purpleidea purpleidea left a comment

Choose a reason for hiding this comment

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

Sweet! Two broad design questions:

  1. Shouldn't resource output contain the types in our type system equivalent instead of what they actually are?

  2. Can we add a --xml flag to produce machine readable output too? We can postpone for a later patch though.

lib/info.go Outdated
if err != nil {
return err
}
w := tabwriter.NewWriter(os.Stdout, 0, 8, 2, ' ', 0)
Copy link
Owner

Choose a reason for hiding this comment

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

Can we have these vars be const (at the top), if only to improve readability please?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure

lib/info.go Outdated
"github.com/urfave/cli"
)

var myPrintln = fmt.Printf
Copy link
Owner

Choose a reason for hiding this comment

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

what's this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

leftover from the wrong approach to capture test output

lib/info.go Outdated
switch c.Command.Name {
case "resources":
for _, name := range resources.RegisteredResourcesNames() {
if name == "test" {
Copy link
Owner

Choose a reason for hiding this comment

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

why skip it? It's real :)

s := reflect.ValueOf(res).Elem()
typeOfT := s.Type()

var fields []string
Copy link
Owner

Choose a reason for hiding this comment

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

use, improve, or add to one of the functions in resources/util.go please,

if anything wouldn't we want the info sub commands to be separate functions?

lib/info.go Outdated
if err != nil {
continue
}
switch fn.(type) {
Copy link
Owner

Choose a reason for hiding this comment

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

_, ok := fn.(interfaces.PolyFunc)

assert.Contains(t, out.String(), "load() struct{x1 float; x5 float; x15 float}")
}

// func TestPolyFunctionsWithTypes(t *testing.T) {
Copy link
Owner

Choose a reason for hiding this comment

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

add or delete?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

scratchpad until i have polyfuncs figured out or for a 2.0 patch of this feature

// return nil
//}

// Lookup returns a pointer to the resource's struct.
Copy link
Owner

Choose a reason for hiding this comment

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

Not sure why we need a helper function for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just mirroring funcs Lookup here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

also registeredResources is private :)

Copy link
Owner

Choose a reason for hiding this comment

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

I didn't realize this was in resources.go :P

lib/info.go Outdated
return nil
}

// infocmd takes the cli context and returns the requested output
Copy link
Owner

Choose a reason for hiding this comment

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

golang style says InfoCmd or infoCmd please, but not sure why this is a separate function altogether

Copy link
Contributor Author

@aequitas aequitas Feb 27, 2018

Choose a reason for hiding this comment

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

to allow unit testing the output without jumping through hoops to capture it (eg: rerouting stdout, etc)

@aequitas
Copy link
Contributor Author

@purpleidea

1: the resource rending is more a hack than a preferred implementation, if you know of a way to get the right output i'm all ears

2: if there is an easy library which can write this to XML in a open format suitable for this kind of data I will add it in, otherwise next patch.

@purpleidea
Copy link
Owner

@aequitas Indeed, there is already such an XML lib as seen in yamlgraph2/ being used.

@aequitas
Copy link
Contributor Author

@purpleidea I don't see any xml reference in yamlgraph2? Can you point me to where it is?

@purpleidea
Copy link
Owner

@aequitas aequitas force-pushed the info branch 2 times, most recently from 69d190a to 281e7b0 Compare February 27, 2018 20:52
@aequitas
Copy link
Contributor Author

@purpleidea so you want xml output or yaml output? :) Why not both? We could maybe use YAML as an intermediate format for XML (and JSON for that matter :D)

@purpleidea
Copy link
Owner

@aequitas Just yaml is sufficient :)

"github.com/urfave/cli"
)

const (
Copy link
Owner

Choose a reason for hiding this comment

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

https://golang.org/doc/effective_go.html#mixed-caps

probably these could be public if you want.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i know, i'm following the names set by the tabwriter package, let me know if you prefer proper go names instead

Copy link
Owner

Choose a reason for hiding this comment

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

oh gosh. Another inconsistency in their own style guide? Gah. Sorry. Do the right thing. If golangv2 fixes these things, we'll be ahead of the curve.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@aequitas aequitas force-pushed the info branch 5 times, most recently from 8144f05 to c855607 Compare March 5, 2018 13:47
@aequitas
Copy link
Contributor Author

#368 (comment)

@aequitas aequitas closed this Mar 13, 2018
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