2024-03-19 00:31:35 +00:00
package main
import (
"os"
"time"
"go.uber.org/zap"
"github.com/status-im/status-go/api"
"github.com/status-im/status-go/protocol"
"github.com/urfave/cli/v2"
)
const LightFlag = "light"
const InteractiveFlag = "interactive"
const CountFlag = "count"
const NameFlag = "name"
const AddFlag = "add"
const PortFlag = "port"
2024-04-09 15:44:43 +00:00
const APIModulesFlag = "api-modules"
2024-05-22 22:01:54 +00:00
const TelemetryServerURLFlag = "telemetry-server-url"
2024-06-12 08:00:51 +00:00
const KeyUIDFlag = "key-uid"
2024-06-14 13:13:31 +00:00
const DebugLevel = "debug"
2024-03-19 00:31:35 +00:00
const RetrieveInterval = 300 * time . Millisecond
const SendInterval = 1 * time . Second
const WaitingInterval = 5 * time . Second
var CommonFlags = [ ] cli . Flag {
& cli . BoolFlag {
Name : LightFlag ,
Aliases : [ ] string { "l" } ,
Usage : "Enable light mode" ,
} ,
2024-04-09 15:44:43 +00:00
& cli . StringFlag {
Name : APIModulesFlag ,
Aliases : [ ] string { "m" } ,
Value : "waku,wakuext,wakuv2,permissions,eth" ,
Usage : "API modules to enable" ,
} ,
2024-05-22 22:01:54 +00:00
& cli . StringFlag {
Name : TelemetryServerURLFlag ,
Aliases : [ ] string { "t" } ,
Usage : "Telemetry server URL" ,
} ,
2024-06-14 13:13:31 +00:00
& cli . BoolFlag {
Name : DebugLevel ,
Aliases : [ ] string { "d" } ,
Usage : "Enable CLI's debug level logging" ,
Value : false ,
} ,
2024-03-19 00:31:35 +00:00
}
2024-04-09 15:44:43 +00:00
var SimulateFlags = append ( [ ] cli . Flag {
2024-03-19 00:31:35 +00:00
& cli . BoolFlag {
Name : InteractiveFlag ,
Aliases : [ ] string { "i" } ,
2024-04-09 15:44:43 +00:00
Usage : "Use interactive mode to input the messages" ,
2024-03-19 00:31:35 +00:00
} ,
& cli . IntFlag {
Name : CountFlag ,
Aliases : [ ] string { "c" } ,
Value : 1 ,
Usage : "How many messages to sent from each user" ,
} ,
} , CommonFlags ... )
var ServeFlags = append ( [ ] cli . Flag {
& cli . StringFlag {
Name : NameFlag ,
Aliases : [ ] string { "n" } ,
Value : "Alice" ,
Usage : "Name of the user" ,
} ,
& cli . StringFlag {
Name : AddFlag ,
Aliases : [ ] string { "a" } ,
Usage : "Add a friend with the public key" ,
} ,
& cli . IntFlag {
Name : PortFlag ,
Aliases : [ ] string { "p" } ,
Value : 8545 ,
Usage : "HTTP Server port to listen on" ,
} ,
2024-06-10 10:21:09 +00:00
& cli . BoolFlag {
Name : InteractiveFlag ,
Aliases : [ ] string { "i" } ,
Usage : "Use interactive mode to input the messages" ,
} ,
2024-03-19 00:31:35 +00:00
} , CommonFlags ... )
type StatusCLI struct {
name string
messenger * protocol . Messenger
backend * api . GethStatusBackend
logger * zap . SugaredLogger
}
func main ( ) {
app := & cli . App {
Commands : [ ] * cli . Command {
{
2024-04-09 15:44:43 +00:00
Name : "simulate" ,
Usage : "Simulate the process of sending direct messages" ,
Flags : SimulateFlags ,
2024-03-19 00:31:35 +00:00
Action : func ( cCtx * cli . Context ) error {
return simulate ( cCtx )
} ,
} ,
{
Name : "serve" ,
Aliases : [ ] string { "s" } ,
Usage : "Start a server to send and receive messages" ,
Flags : ServeFlags ,
Action : func ( cCtx * cli . Context ) error {
2024-06-14 13:13:31 +00:00
return serve ( cCtx )
2024-06-12 08:00:51 +00:00
} ,
} ,
{
Name : "serve-account" ,
Aliases : [ ] string { "sl" } ,
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'" ,
Flags : [ ] cli . Flag {
& cli . StringFlag {
Name : NameFlag ,
Aliases : [ ] string { "n" } ,
Usage : "Name of the existing user" ,
Required : true ,
} ,
& cli . StringFlag {
2024-06-14 13:13:31 +00:00
Name : KeyUIDFlag ,
Aliases : [ ] string { "kid" } ,
Usage : "Key ID of the existing user (find them under '<data-dir>/keystore' on in logs when using the 'serve' command)" ,
Required : true ,
2024-06-12 08:00:51 +00:00
} ,
& cli . BoolFlag {
Name : InteractiveFlag ,
Aliases : [ ] string { "i" } ,
Usage : "Use interactive mode to input the messages" ,
2024-06-14 13:13:31 +00:00
Value : false ,
2024-06-12 08:00:51 +00:00
} ,
& cli . StringFlag {
Name : AddFlag ,
Aliases : [ ] string { "a" } ,
Usage : "Add a friend with the public key" ,
} ,
2024-06-14 13:13:31 +00:00
& cli . BoolFlag {
Name : DebugLevel ,
Aliases : [ ] string { "d" } ,
Usage : "Enable CLI's debug level logging" ,
Value : false ,
} ,
2024-06-12 08:00:51 +00:00
} ,
Action : func ( cCtx * cli . Context ) error {
2024-06-14 13:13:31 +00:00
return serve ( cCtx )
2024-03-19 00:31:35 +00:00
} ,
} ,
} ,
}
if err := app . Run ( os . Args ) ; err != nil {
2024-06-14 13:13:31 +00:00
zap . L ( ) . Fatal ( "main" , zap . Error ( err ) )
2024-03-19 00:31:35 +00:00
}
}