2018-03-30 16:15:06 +00:00
|
|
|
package vm
|
|
|
|
|
|
|
|
import (
|
2022-10-03 12:05:48 +00:00
|
|
|
"fmt"
|
2021-02-10 08:53:01 +00:00
|
|
|
"os"
|
|
|
|
|
2022-02-15 12:55:25 +00:00
|
|
|
"github.com/chzyer/readline"
|
2022-08-05 10:32:37 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/cli/cmdargs"
|
2022-10-03 12:05:48 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/cli/options"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/core/storage/dbconfig"
|
2018-03-30 16:15:06 +00:00
|
|
|
"github.com/urfave/cli"
|
|
|
|
)
|
|
|
|
|
2019-10-19 20:58:45 +00:00
|
|
|
// NewCommands returns 'vm' command.
|
|
|
|
func NewCommands() []cli.Command {
|
2023-05-12 13:53:57 +00:00
|
|
|
cfgFlags := []cli.Flag{options.Config, options.ConfigFile}
|
2022-10-03 12:05:48 +00:00
|
|
|
cfgFlags = append(cfgFlags, options.Network...)
|
2019-10-19 20:58:45 +00:00
|
|
|
return []cli.Command{{
|
2018-03-30 16:15:06 +00:00
|
|
|
Name: "vm",
|
|
|
|
Usage: "start the virtual machine",
|
|
|
|
Action: startVMPrompt,
|
2022-10-03 12:05:48 +00:00
|
|
|
Flags: cfgFlags,
|
2019-10-19 20:58:45 +00:00
|
|
|
}}
|
2018-03-30 16:15:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func startVMPrompt(ctx *cli.Context) error {
|
2022-08-05 10:32:37 +00:00
|
|
|
if err := cmdargs.EnsureNone(ctx); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-10-03 12:05:48 +00:00
|
|
|
|
|
|
|
cfg, err := options.GetConfigFromContext(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return cli.NewExitError(err, 1)
|
|
|
|
}
|
|
|
|
if ctx.NumFlags() == 0 {
|
|
|
|
cfg.ApplicationConfiguration.DBConfiguration.Type = dbconfig.InMemoryDB
|
|
|
|
}
|
|
|
|
if cfg.ApplicationConfiguration.DBConfiguration.Type != dbconfig.InMemoryDB {
|
|
|
|
cfg.ApplicationConfiguration.DBConfiguration.LevelDBOptions.ReadOnly = true
|
|
|
|
cfg.ApplicationConfiguration.DBConfiguration.BoltDBOptions.ReadOnly = true
|
|
|
|
}
|
|
|
|
|
|
|
|
p, err := NewWithConfig(true, os.Exit, &readline.Config{}, cfg)
|
|
|
|
if err != nil {
|
|
|
|
return cli.NewExitError(fmt.Errorf("failed to create VM CLI: %w", err), 1)
|
|
|
|
}
|
2018-03-30 16:15:06 +00:00
|
|
|
return p.Run()
|
|
|
|
}
|