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

Add --format option to mfs stat command #2706

Merged
merged 5 commits into from
May 18, 2016
Merged

Conversation

Kubuxu
Copy link
Member

@Kubuxu Kubuxu commented May 16, 2016

also add --hash and --size of hash and size only formats

This was on my QoL change list for a long time.
Resolves: #2461

License: MIT
Signed-off-by: Jakub Sztandera [email protected]

also add --hash and --size of hash and size only formats

License: MIT
Signed-off-by: Jakub Sztandera <[email protected]>
}
if count > 1 {
return "", formatError
}
Copy link
Member Author

Choose a reason for hiding this comment

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

I am 100% sure there is better pattern to do it. My C tainted mind where I would just add them couldn't find it.

Copy link
Member

Choose a reason for hiding this comment

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

i think this works:

func moreThanOne(a,b,c bool) bool {
    return !((a == b == c) && !(a && b && c)) && (a || b || c)
}

it can probably be reduced...

Copy link
Member

Choose a reason for hiding this comment

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

better:
return a && b || b && c || a && c

Copy link
Member Author

Choose a reason for hiding this comment

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

Right, it is so easy 😢 😄

License: MIT
Signed-off-by: Jakub Sztandera <[email protected]>
return a && b || b && c || a && c
}

func statGetFormatOptions(req cmds.Request) (string, error) {
Copy link
Member

Choose a reason for hiding this comment

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

i'd write this function as:

hash, _, _ := req.Option("hash").Bool()
size, _, _ := req.Option("size").Bool()
format, found, _ := req.Option("format").Found()

if moreThanOne(hash, size, found) {
    return "", formatError
}

if hash {
    return "<hash>", nil
} else if size {
    return "<cumulsize>", nil
} else {
    return format, nil
}

Copy link
Member Author

@Kubuxu Kubuxu May 17, 2016

Choose a reason for hiding this comment

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

Will do, I was quite sleepy when I was doing it.
EDIT: done

@Kubuxu Kubuxu added the need/review Needs a review label May 17, 2016
License: MIT
Signed-off-by: Jakub Sztandera <[email protected]>
@whyrusleeping
Copy link
Member

sweet, now throw a test in there and we're good to go 👍

License: MIT
Signed-off-by: Jakub Sztandera <[email protected]>
License: MIT
Signed-off-by: Jakub Sztandera <[email protected]>
@whyrusleeping
Copy link
Member

LGTM

@whyrusleeping whyrusleeping merged commit 6f71646 into master May 18, 2016
@whyrusleeping whyrusleeping deleted the feature/MFSStatsHashOnly branch May 18, 2016 20:47
Options: []cmds.Option{
cmds.StringOption("format", "Print statistics in given format. Allowed tokens: "+
"<hash> <size> <cumulsize> <type> <childs>. Conflicts with other format options.").Default(
`<hash>
Copy link
Member

Choose a reason for hiding this comment

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

This should be prefixed with Hash: <hash> -- otherwise it only prints the hash in one line and then Key: Value format.

Copy link
Member

Choose a reason for hiding this comment

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

I know this was this way in the past-- it seems like it was a bug.

Copy link
Member Author

Choose a reason for hiding this comment

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

It was always like that, changing it would break CLI compatibility.

It is so you could do ipfs files stat /file | head -1 to get the hash before format options were a thing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need/review Needs a review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants