github.com/status-im/status-go@v1.1.0/cmd/status-cli/main.go (about)

     1  package main
     2  
     3  import (
     4  	"log"
     5  	"os"
     6  	"time"
     7  
     8  	"go.uber.org/zap"
     9  
    10  	"github.com/status-im/status-go/api"
    11  	"github.com/status-im/status-go/protocol"
    12  
    13  	"github.com/urfave/cli/v2"
    14  )
    15  
    16  const LightFlag = "light"
    17  const InteractiveFlag = "interactive"
    18  const CountFlag = "count"
    19  const NameFlag = "name"
    20  const AddFlag = "add"
    21  const PortFlag = "port"
    22  const APIModulesFlag = "api-modules"
    23  const TelemetryServerURLFlag = "telemetry-server-url"
    24  const KeyUIDFlag = "key-uid"
    25  const FleetFlag = "fleet"
    26  const DebugLevel = "debug"
    27  const MessageFailureFlag = "fail"
    28  
    29  const RetrieveInterval = 300 * time.Millisecond
    30  const SendInterval = 1 * time.Second
    31  const WaitingInterval = 5 * time.Second
    32  
    33  var CommonFlags = []cli.Flag{
    34  	&cli.BoolFlag{
    35  		Name:    LightFlag,
    36  		Aliases: []string{"l"},
    37  		Usage:   "Enable light mode",
    38  	},
    39  	&cli.StringFlag{
    40  		Name:    APIModulesFlag,
    41  		Aliases: []string{"m"},
    42  		Value:   "waku,wakuext,wakuv2,permissions,eth",
    43  		Usage:   "API modules to enable",
    44  	},
    45  	&cli.StringFlag{
    46  		Name:    TelemetryServerURLFlag,
    47  		Aliases: []string{"t"},
    48  		Usage:   "Telemetry server URL",
    49  	},
    50  	&cli.BoolFlag{
    51  		Name:    DebugLevel,
    52  		Aliases: []string{"d"},
    53  		Usage:   "Enable CLI's debug level logging",
    54  		Value:   false,
    55  	},
    56  	&cli.StringFlag{
    57  		Name:     FleetFlag,
    58  		Aliases:  []string{"f"},
    59  		Usage:    "The fleet to use for the node, e.g.: status.staging, status.prod",
    60  		Value:    "status.staging",
    61  		Required: false,
    62  	},
    63  }
    64  
    65  var SimulateFlags = append([]cli.Flag{
    66  	&cli.BoolFlag{
    67  		Name:    InteractiveFlag,
    68  		Aliases: []string{"i"},
    69  		Usage:   "Use interactive mode to input the messages",
    70  	},
    71  	&cli.IntFlag{
    72  		Name:    CountFlag,
    73  		Aliases: []string{"c"},
    74  		Value:   1,
    75  		Usage:   "How many messages to sent from each user",
    76  	},
    77  	&cli.BoolFlag{
    78  		Name:  MessageFailureFlag,
    79  		Usage: "Causes messages to fail about 25% of the time",
    80  		Value: false,
    81  	},
    82  }, CommonFlags...)
    83  
    84  var ServeFlags = append([]cli.Flag{
    85  	&cli.StringFlag{
    86  		Name:    NameFlag,
    87  		Aliases: []string{"n"},
    88  		Value:   "Alice",
    89  		Usage:   "Name of the user",
    90  	},
    91  	&cli.StringFlag{
    92  		Name:    AddFlag,
    93  		Aliases: []string{"a"},
    94  		Usage:   "Add a friend with the public key",
    95  	},
    96  	&cli.IntFlag{
    97  		Name:    PortFlag,
    98  		Aliases: []string{"p"},
    99  		Value:   8545,
   100  		Usage:   "HTTP Server port to listen on",
   101  	},
   102  	&cli.BoolFlag{
   103  		Name:    InteractiveFlag,
   104  		Aliases: []string{"i"},
   105  		Usage:   "Use interactive mode to input the messages",
   106  	},
   107  }, CommonFlags...)
   108  
   109  type StatusCLI struct {
   110  	name      string
   111  	messenger *protocol.Messenger
   112  	backend   *api.GethStatusBackend
   113  	logger    *zap.SugaredLogger
   114  }
   115  
   116  func main() {
   117  	app := &cli.App{
   118  		Commands: []*cli.Command{
   119  			{
   120  				Name:  "simulate",
   121  				Usage: "Simulate the process of sending direct messages",
   122  				Flags: SimulateFlags,
   123  				Action: func(cCtx *cli.Context) error {
   124  					return simulate(cCtx)
   125  				},
   126  			},
   127  			{
   128  				Name:    "serve",
   129  				Aliases: []string{"s"},
   130  				Usage:   "Start a server to send and receive messages",
   131  				Flags:   ServeFlags,
   132  				Action: func(cCtx *cli.Context) error {
   133  					return serve(cCtx)
   134  				},
   135  			},
   136  			{
   137  				Name:    "serve-account",
   138  				Aliases: []string{"sl"},
   139  				Usage:   "Start a server with the lastest input name's account\n\n  E.g.: if last time you created an account with name 'Alice',\n  you can start the server with 'Alice' account by running 'servelast -n Alice'",
   140  				Flags: []cli.Flag{
   141  					&cli.StringFlag{
   142  						Name:     NameFlag,
   143  						Aliases:  []string{"n"},
   144  						Usage:    "Name of the existing user",
   145  						Required: true,
   146  					},
   147  					&cli.StringFlag{
   148  						Name:     KeyUIDFlag,
   149  						Aliases:  []string{"kid"},
   150  						Usage:    "Key ID of the existing user (find them under '<data-dir>/keystore' on in logs when using the 'serve' command)",
   151  						Required: true,
   152  					},
   153  					&cli.BoolFlag{
   154  						Name:    InteractiveFlag,
   155  						Aliases: []string{"i"},
   156  						Usage:   "Use interactive mode to input the messages",
   157  						Value:   false,
   158  					},
   159  					&cli.StringFlag{
   160  						Name:    AddFlag,
   161  						Aliases: []string{"a"},
   162  						Usage:   "Add a friend with the public key",
   163  					},
   164  					&cli.BoolFlag{
   165  						Name:    DebugLevel,
   166  						Aliases: []string{"d"},
   167  						Usage:   "Enable CLI's debug level logging",
   168  						Value:   false,
   169  					},
   170  				},
   171  				Action: func(cCtx *cli.Context) error {
   172  					return serve(cCtx)
   173  				},
   174  			},
   175  		},
   176  	}
   177  
   178  	if err := app.Run(os.Args); err != nil {
   179  		log.Fatal(err)
   180  	}
   181  }