-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Conversation
also add --hash and --size of hash and size only formats License: MIT Signed-off-by: Jakub Sztandera <kubuxu@protonmail.ch>
} | ||
if count > 1 { | ||
return "", formatError | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 <kubuxu@protonmail.ch>
7e71d4b
to
94f1922
Compare
return a && b || b && c || a && c | ||
} | ||
|
||
func statGetFormatOptions(req cmds.Request) (string, error) { |
There was a problem hiding this comment.
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
}
There was a problem hiding this comment.
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
276a47f
to
797dee5
Compare
License: MIT Signed-off-by: Jakub Sztandera <kubuxu@protonmail.ch>
797dee5
to
130c08c
Compare
sweet, now throw a test in there and we're good to go 👍 |
License: MIT Signed-off-by: Jakub Sztandera <kubuxu@protonmail.ch>
License: MIT Signed-off-by: Jakub Sztandera <kubuxu@protonmail.ch>
LGTM |
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> |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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 kubuxu@protonmail.ch