cli: allow to use vm parse
directly
This commit is contained in:
parent
ef53a45e7a
commit
227c6a2caa
3 changed files with 54 additions and 8 deletions
|
@ -454,11 +454,20 @@ func (c *VMCLI) Run() error {
|
|||
}
|
||||
|
||||
func handleParse(c *ishell.Context) {
|
||||
if len(c.Args) < 1 {
|
||||
c.Err(errors.New("missing argument"))
|
||||
res, err := Parse(c.Args)
|
||||
if err != nil {
|
||||
c.Err(err)
|
||||
return
|
||||
}
|
||||
arg := c.Args[0]
|
||||
c.Print(res)
|
||||
}
|
||||
|
||||
// Parse converts it's argument to other formats.
|
||||
func Parse(args []string) (string, error) {
|
||||
if len(args) < 1 {
|
||||
return "", errors.New("missing argument")
|
||||
}
|
||||
arg := args[0]
|
||||
buf := bytes.NewBuffer(nil)
|
||||
if val, err := strconv.ParseInt(arg, 10, 64); err == nil {
|
||||
bs := bigint.ToBytes(big.NewInt(val))
|
||||
|
@ -493,14 +502,12 @@ func handleParse(c *ishell.Context) {
|
|||
buf = bytes.NewBuffer(nil)
|
||||
w := tabwriter.NewWriter(buf, 0, 0, 4, ' ', 0)
|
||||
if _, err := w.Write(out); err != nil {
|
||||
c.Err(err)
|
||||
return
|
||||
return "", err
|
||||
}
|
||||
if err := w.Flush(); err != nil {
|
||||
c.Err(err)
|
||||
return
|
||||
return "", err
|
||||
}
|
||||
c.Print(string(buf.Bytes()))
|
||||
return string(buf.Bytes()), nil
|
||||
}
|
||||
|
||||
func parseArgs(args []string) ([]stackitem.Item, error) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue