Add cmdf and cmdjf

This commit is contained in:
rhl120 authored and pancake committed 2021-11-21 18:55:31 +01:00
1 parent 12856ecd14
commit 19ec5a7bdd
1 file changed
+10
+10
View File
@@ -171,6 +171,11 @@ func (r2p *Pipe) Cmd(cmd string) (string, error) {
return strings.TrimRight(buf, "\n\x00"), nil
}
//like cmd but formats the command
func (r2p *Pipe) Cmdf(f string, args ...interface{}) (string, error) {
return r2p.Cmd(fmt.Sprintf(f, args...))
}
// Cmdj acts like Cmd but interprets the output of the command as json. It
// returns the parsed json keys and values.
func (r2p *Pipe) Cmdj(cmd string) (interface{}, error) {
@@ -194,6 +199,11 @@ func (r2p *Pipe) Cmdj(cmd string) (interface{}, error) {
return output, nil
}
//like cmdj but formats the command
func (r2p *Pipe) Cmdjf(f string, args ...interface{}) (interface{}, error) {
return r2p.Cmdj(fmt.Sprintf(f, args...))
}
// Close shuts down r2, closing the created pipe.
func (r2p *Pipe) Close() error {
if r2p.close != nil {