forked from Silverfish/proton-bridge
GODT-2013: CLI flag for frontend is required.
Other: removed --ni flag alias.
This commit is contained in:
@ -69,12 +69,13 @@ const (
|
|||||||
flagMemProfileShort = "m"
|
flagMemProfileShort = "m"
|
||||||
flagLogLevel = "log-level"
|
flagLogLevel = "log-level"
|
||||||
flagLogLevelShort = "l"
|
flagLogLevelShort = "l"
|
||||||
// FlagCLI indicate to start with command line interface.
|
FlagGRPC = "grpc" // FlagGRPC starts the gRPC frontend
|
||||||
FlagCLI = "cli"
|
FlagGRPCShort = "g"
|
||||||
flagCLIShort = "c"
|
FlagCLI = "cli" // FlagCLI indicate to start with command line interface.
|
||||||
flagRestart = "restart"
|
flagCLIShort = "c"
|
||||||
FlagLauncher = "launcher"
|
flagRestart = "restart"
|
||||||
FlagNoWindow = "no-window"
|
FlagLauncher = "launcher"
|
||||||
|
FlagNoWindow = "no-window"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Base struct {
|
type Base struct {
|
||||||
@ -299,6 +300,11 @@ func (b *Base) NewApp(mainLoop func(*Base, *cli.Context) error) *cli.App {
|
|||||||
Aliases: []string{flagLogLevelShort},
|
Aliases: []string{flagLogLevelShort},
|
||||||
Usage: "Set the log level (one of panic, fatal, error, warn, info, debug)",
|
Usage: "Set the log level (one of panic, fatal, error, warn, info, debug)",
|
||||||
},
|
},
|
||||||
|
&cli.BoolFlag{
|
||||||
|
Name: FlagGRPC,
|
||||||
|
Aliases: []string{FlagGRPCShort},
|
||||||
|
Usage: "Start the gRPC service",
|
||||||
|
},
|
||||||
&cli.BoolFlag{
|
&cli.BoolFlag{
|
||||||
Name: FlagCLI,
|
Name: FlagCLI,
|
||||||
Aliases: []string{flagCLIShort},
|
Aliases: []string{flagCLIShort},
|
||||||
|
|||||||
@ -40,10 +40,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
flagLogIMAP = "log-imap"
|
flagLogIMAP = "log-imap"
|
||||||
flagLogSMTP = "log-smtp"
|
flagLogSMTP = "log-smtp"
|
||||||
flagNonInteractive = "noninteractive"
|
flagNonInteractive = "noninteractive"
|
||||||
|
flagNonInteractiveShort = "n"
|
||||||
// Memory cache was estimated by empirical usage in the past, and it was set to 100MB.
|
// Memory cache was estimated by empirical usage in the past, and it was set to 100MB.
|
||||||
// NOTE: This value must not be less than maximal size of one email (~30MB).
|
// NOTE: This value must not be less than maximal size of one email (~30MB).
|
||||||
inMemoryCacheLimit = 100 * (1 << 20)
|
inMemoryCacheLimit = 100 * (1 << 20)
|
||||||
@ -62,8 +62,9 @@ func New(base *base.Base) *cli.App {
|
|||||||
Usage: "Enable logging of SMTP communications (may contain decrypted data!)",
|
Usage: "Enable logging of SMTP communications (may contain decrypted data!)",
|
||||||
},
|
},
|
||||||
&cli.BoolFlag{
|
&cli.BoolFlag{
|
||||||
Name: flagNonInteractive,
|
Name: flagNonInteractive,
|
||||||
Usage: "Start Bridge entirely non-interactively",
|
Aliases: []string{flagNonInteractiveShort},
|
||||||
|
Usage: "Start Bridge entirely non-interactively",
|
||||||
},
|
},
|
||||||
}...)
|
}...)
|
||||||
|
|
||||||
@ -72,6 +73,11 @@ func New(base *base.Base) *cli.App {
|
|||||||
|
|
||||||
func main(b *base.Base, c *cli.Context) error { //nolint:funlen
|
func main(b *base.Base, c *cli.Context) error { //nolint:funlen
|
||||||
frontendType := getFrontendTypeFromCLIParams(c)
|
frontendType := getFrontendTypeFromCLIParams(c)
|
||||||
|
if frontendType == frontend.Unknown {
|
||||||
|
_ = cli.ShowAppHelp(c)
|
||||||
|
return errors.New("no frontend was specified. Use --grpc, --cli or --noninteractive")
|
||||||
|
}
|
||||||
|
|
||||||
f := frontend.New(
|
f := frontend.New(
|
||||||
frontendType,
|
frontendType,
|
||||||
!c.Bool(base.FlagNoWindow),
|
!c.Bool(base.FlagNoWindow),
|
||||||
@ -171,12 +177,14 @@ func main(b *base.Base, c *cli.Context) error { //nolint:funlen
|
|||||||
|
|
||||||
func getFrontendTypeFromCLIParams(c *cli.Context) frontend.Type {
|
func getFrontendTypeFromCLIParams(c *cli.Context) frontend.Type {
|
||||||
switch {
|
switch {
|
||||||
|
case c.Bool(base.FlagGRPC):
|
||||||
|
return frontend.GRPC
|
||||||
case c.Bool(base.FlagCLI):
|
case c.Bool(base.FlagCLI):
|
||||||
return frontend.CLI
|
return frontend.CLI
|
||||||
case c.Bool(flagNonInteractive):
|
case c.Bool(flagNonInteractive):
|
||||||
return frontend.NonInteractive
|
return frontend.NonInteractive
|
||||||
default:
|
default:
|
||||||
return frontend.GRPC
|
return frontend.Unknown
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -200,7 +200,7 @@ void launchBridge(QStringList const &args)
|
|||||||
else
|
else
|
||||||
app().log().debug(QString("Bridge executable path: %1").arg(QDir::toNativeSeparators(bridgeExePath)));
|
app().log().debug(QString("Bridge executable path: %1").arg(QDir::toNativeSeparators(bridgeExePath)));
|
||||||
|
|
||||||
overseer = std::make_unique<Overseer>(new ProcessMonitor(bridgeExePath, args, nullptr), nullptr);
|
overseer = std::make_unique<Overseer>(new ProcessMonitor(bridgeExePath, QStringList("--grpc") + args, nullptr), nullptr);
|
||||||
overseer->startWorker(true);
|
overseer->startWorker(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -25,6 +25,7 @@ import (
|
|||||||
"github.com/ProtonMail/proton-bridge/v2/internal/locations"
|
"github.com/ProtonMail/proton-bridge/v2/internal/locations"
|
||||||
"github.com/ProtonMail/proton-bridge/v2/internal/updater"
|
"github.com/ProtonMail/proton-bridge/v2/internal/updater"
|
||||||
"github.com/ProtonMail/proton-bridge/v2/pkg/listener"
|
"github.com/ProtonMail/proton-bridge/v2/pkg/listener"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Type describes the available types of frontend.
|
// Type describes the available types of frontend.
|
||||||
@ -34,6 +35,7 @@ const (
|
|||||||
CLI Type = iota
|
CLI Type = iota
|
||||||
GRPC
|
GRPC
|
||||||
NonInteractive
|
NonInteractive
|
||||||
|
Unknown
|
||||||
)
|
)
|
||||||
|
|
||||||
type Frontend interface {
|
type Frontend interface {
|
||||||
@ -45,7 +47,7 @@ type Frontend interface {
|
|||||||
WaitUntilFrontendIsReady()
|
WaitUntilFrontendIsReady()
|
||||||
}
|
}
|
||||||
|
|
||||||
// New returns initialized frontend based on `frontendType`, which can be `CLI` or `GRPC`.
|
// New returns initialized frontend based on `frontendType`, which can be `CLI` or `GRPC`. Non-interactive will return a nil frontend.
|
||||||
func New(
|
func New(
|
||||||
frontendType Type,
|
frontendType Type,
|
||||||
showWindowOnStart bool,
|
showWindowOnStart bool,
|
||||||
@ -75,9 +77,13 @@ func New(
|
|||||||
)
|
)
|
||||||
|
|
||||||
case NonInteractive:
|
case NonInteractive:
|
||||||
|
return nil
|
||||||
|
|
||||||
|
case Unknown:
|
||||||
fallthrough
|
fallthrough
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return nil
|
logrus.Panicf("Unexpected frontend value %v", frontendType)
|
||||||
|
return nil // return statement is required by compiler, although the above call will panic.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user