gosuki/cmd/firefox_flags.go

77 lines
1.3 KiB
Go
Raw Normal View History

2019-02-27 16:39:55 +00:00
package cmd
import (
"strings"
2020-08-12 18:13:01 +00:00
"git.sp4ke.com/sp4ke/gomark/config"
"git.sp4ke.com/sp4ke/gomark/mozilla"
"git.sp4ke.com/sp4ke/gomark/utils"
2020-08-12 18:13:01 +00:00
2019-02-27 16:39:55 +00:00
"github.com/gobuffalo/flect"
2020-08-12 18:13:01 +00:00
"github.com/urfave/cli/v2"
2019-02-27 16:39:55 +00:00
)
const (
FirefoxDefaultProfileFlag = "firefox-default-profile"
)
var FirefoxGlobalFlags = []cli.Flag{
2020-08-12 18:13:01 +00:00
&cli.StringFlag{
2019-02-27 16:39:55 +00:00
Name: FirefoxDefaultProfileFlag,
Usage: "Set the default firefox `PROFILE` to use",
},
}
func GlobalFirefoxFlagsManager(c *cli.Context) error {
for _, f := range c.App.Flags {
if utils.Ins(f.Names(), "help") ||
utils.Ins(f.Names(), "version") {
continue
}
2020-09-17 05:42:21 +00:00
//TODO: is set is not detected here !
if !f.IsSet() {
continue
}
sp := strings.Split(f.Names()[0], "-")
2019-02-27 16:39:55 +00:00
if len(sp) < 2 {
continue
}
if sp[0] != "firefox" {
continue
}
optionName := flect.Pascalize(strings.Join(sp[1:], " "))
2020-09-17 05:43:04 +00:00
fflog.Debugf("Option name %s", optionName)
2019-02-27 16:39:55 +00:00
var destVal interface{}
// Find the corresponding flag
for _, ff := range FirefoxGlobalFlags {
if ff.String() == f.String() {
2019-02-27 16:39:55 +00:00
// Type switch on the flag type
switch ff.(type) {
case *cli.StringFlag:
destVal = f.Names()[0]
2019-02-27 16:39:55 +00:00
}
}
}
err := config.RegisterModuleOpt(mozilla.ConfigName,
optionName, destVal)
if err != nil {
fflog.Fatal(err)
}
2019-02-27 16:39:55 +00:00
}
return nil
}