fixed: ff custom module flags, setting module opts from flags
This commit is contained in:
parent
9a78dd8099
commit
2ca7c6f72b
@ -47,7 +47,7 @@ const (
|
||||
var (
|
||||
|
||||
// firefox global config state.
|
||||
FFConfig = NewFirefoxConfig()
|
||||
FFConfig *FirefoxConfig
|
||||
|
||||
ffProfileLoader = &profiles.INIProfileLoader{
|
||||
//BasePath to be set at runtime in init
|
||||
@ -150,21 +150,19 @@ func NewFirefoxConfig() *FirefoxConfig {
|
||||
|
||||
|
||||
func init() {
|
||||
FFConfig = NewFirefoxConfig()
|
||||
config.RegisterConfigurator(BrowserName, config.AsConfigurator(FFConfig))
|
||||
config.RegisterConfReadyHooks(func(*cli.Context) error{
|
||||
|
||||
// log.Debugf("%p", FFConfig)
|
||||
|
||||
// An example of running custom code when config is ready
|
||||
config.RegisterConfReadyHooks(func(c *cli.Context) error{
|
||||
// log.Debugf("%#v", config.GetAll().Dump())
|
||||
|
||||
|
||||
//FIX: WatchAllProfiles option not set when instanciating new
|
||||
//browser in daemon.go
|
||||
// Recover Watch All Profiles value
|
||||
if userConf := config.GetModule(BrowserName); userConf != nil {
|
||||
watchAll, err := userConf.Get("WatchAllProfiles")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
} else {
|
||||
FFConfig.WatchAllProfiles = watchAll.(bool)
|
||||
}
|
||||
watchAll, _ := userConf.Get("WatchAllProfiles")
|
||||
log.Debugf("WATCH_ALL: %v", watchAll)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -39,7 +39,6 @@ import (
|
||||
"git.blob42.xyz/gosuki/gosuki/pkg/modules"
|
||||
"git.blob42.xyz/gosuki/gosuki/pkg/profiles"
|
||||
|
||||
// "git.blob42.xyz/gosuki/gosuki/pkg/profiles"
|
||||
"git.blob42.xyz/gosuki/gosuki/internal/utils"
|
||||
"git.blob42.xyz/gosuki/gosuki/pkg/tree"
|
||||
"git.blob42.xyz/gosuki/gosuki/pkg/watch"
|
||||
@ -277,7 +276,7 @@ func (*Firefox) GetProfiles(flavour string) ([]*profiles.Profile, error) {
|
||||
|
||||
// If should watch all profiles
|
||||
func (f *Firefox) WatchAllProfiles() bool {
|
||||
return f.FirefoxConfig.WatchAllProfiles
|
||||
return FFConfig.WatchAllProfiles
|
||||
}
|
||||
|
||||
// Use custom profile
|
||||
@ -310,7 +309,7 @@ func (f *Firefox) Init(ctx *modules.Context, p *profiles.Profile) error {
|
||||
}
|
||||
|
||||
// use a new config for this profile
|
||||
f.FirefoxConfig = NewFirefoxConfig()
|
||||
// f.FirefoxConfig = NewFirefoxConfig()
|
||||
f.Profile = p.Name
|
||||
|
||||
|
||||
|
@ -47,9 +47,7 @@ func initConfig() {
|
||||
|
||||
if !exists {
|
||||
// Initialize default initConfig
|
||||
//NOTE: if custom flags are passed before config.toml exists, falg
|
||||
//options will not be saved to the initial config.toml, this means
|
||||
//command line flags have higher priority than config.toml
|
||||
//NOTE: flags have higher priority than config file
|
||||
initDefaultConfig()
|
||||
} else {
|
||||
err = config.LoadFromTomlFile()
|
||||
|
@ -151,8 +151,10 @@ func startDaemon(c *cli.Context) error {
|
||||
log.Criticalf("TODO: module <%s> is not a BrowserModule", mod.ID)
|
||||
}
|
||||
|
||||
//BUG: WatchAllProfiles `module` flag option not working here
|
||||
// if the module is a profile manager and is watching all profiles
|
||||
if c.Bool("watch-all") {
|
||||
panic("TODO: watch all profiles")
|
||||
}
|
||||
|
||||
// call runModule for each profile
|
||||
bpm, ok := browser.(profiles.ProfileManager)
|
||||
if ok {
|
||||
|
@ -27,8 +27,8 @@ import (
|
||||
|
||||
"git.blob42.xyz/gosuki/gosuki/internal/config"
|
||||
"git.blob42.xyz/gosuki/gosuki/internal/logging"
|
||||
"git.blob42.xyz/gosuki/gosuki/pkg/modules"
|
||||
"git.blob42.xyz/gosuki/gosuki/internal/utils"
|
||||
"git.blob42.xyz/gosuki/gosuki/pkg/modules"
|
||||
|
||||
"git.blob42.xyz/gosuki/gosuki/cmd"
|
||||
|
||||
@ -36,12 +36,11 @@ import (
|
||||
|
||||
// Load firefox browser modules
|
||||
_ "git.blob42.xyz/gosuki/gosuki/browsers/firefox"
|
||||
|
||||
// Load chrome browser module
|
||||
_ "git.blob42.xyz/gosuki/gosuki/browsers/chrome"
|
||||
)
|
||||
|
||||
var log = logging.GetLogger("")
|
||||
var log = logging.GetLogger("MAIN")
|
||||
|
||||
|
||||
func main() {
|
||||
@ -75,8 +74,19 @@ func main() {
|
||||
flags = append(flags, config.SetupGlobalFlags()...)
|
||||
app.Flags = append(app.Flags, flags...)
|
||||
|
||||
|
||||
app.Before = func(c *cli.Context) error {
|
||||
|
||||
// The order here is important
|
||||
//
|
||||
// 1. we load the file config
|
||||
// 2. every module has the opprtunity to register its own flags
|
||||
// 3. the modules can run custom code before the CLI is ready but after
|
||||
// the config is ready, using the config hooks.
|
||||
//
|
||||
// Cli flags have the highest priority and override config file values
|
||||
|
||||
initConfig()
|
||||
|
||||
// get all registered browser modules
|
||||
modules := modules.GetModules()
|
||||
@ -93,14 +103,15 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Execute config hooks
|
||||
//TODO: better doc for what are Conf hooks ???
|
||||
// DOC: better documentation of Conf hooks ???
|
||||
// modules can run custom code before the CLI is ready.
|
||||
// For example read the environment and set configuration options to be
|
||||
// used by the module instances.
|
||||
config.RunConfHooks(c)
|
||||
|
||||
initConfig()
|
||||
|
||||
|
||||
return nil
|
||||
}
|
||||
@ -140,11 +151,14 @@ func main() {
|
||||
if err := app.Run(os.Args); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
// log.Debugf("flags: %s", app.Flags)
|
||||
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
||||
//TODO: watch all profiles (handled at browser level for now)
|
||||
// config.RegisterGlobalOption("all-profiles", false)
|
||||
config.RegisterGlobalOption("watch-all", false)
|
||||
}
|
||||
|
||||
|
@ -125,7 +125,12 @@ func RegisterGlobalOption(key string, val interface{}) {
|
||||
func RegisterModuleOpt(module string, opt string, val interface{}) error {
|
||||
log.Debugf("Setting option for module <%s>: %s = %v", module, opt, val)
|
||||
dest := configs[module]
|
||||
return dest.Set(opt, val)
|
||||
if err := dest.Set(opt, val); err != nil {
|
||||
return err
|
||||
}
|
||||
watchAll, _ := configs[module].Get("WatchAllProfiles")
|
||||
log.Debugf("[%s]WATCH_ALL: %v", module, watchAll)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Get all configs as a map[string]interface{}
|
||||
|
Loading…
Reference in New Issue
Block a user