
This adds a `-wizard` CLI option to the Manager, which opens a webbrowser and shows the First-Time Wizard to aid in configuration of Flamenco. This is work in progress. The wizard is just one page, and doesn't save anything yet to the configuration.
84 lines
1.9 KiB
Go
84 lines
1.9 KiB
Go
package config
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"io/fs"
|
|
|
|
"github.com/rs/zerolog/log"
|
|
)
|
|
|
|
// Service provides access to Flamenco Manager configuration.
|
|
type Service struct {
|
|
config Conf
|
|
forceFirstRun bool
|
|
}
|
|
|
|
func NewService() *Service {
|
|
return &Service{
|
|
config: DefaultConfig(),
|
|
}
|
|
}
|
|
|
|
// IsFirstRun returns true if this is likely to be the first run of Flamenco.
|
|
func (s *Service) IsFirstRun() (bool, error) {
|
|
if s.forceFirstRun {
|
|
return true, nil
|
|
}
|
|
|
|
config, err := getConf()
|
|
switch {
|
|
case errors.Is(err, fs.ErrNotExist):
|
|
// No configuration means first run.
|
|
return false, nil
|
|
case err != nil:
|
|
return false, fmt.Errorf("loading %s: %w", configFilename, err)
|
|
}
|
|
|
|
// No shared storage configured means first run.
|
|
return config.SharedStoragePath == "", nil
|
|
}
|
|
|
|
func (s *Service) ForceFirstRun() {
|
|
s.forceFirstRun = true
|
|
}
|
|
|
|
func (s *Service) Load() error {
|
|
config, err := getConf()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
s.config = config
|
|
return nil
|
|
}
|
|
|
|
func (s *Service) Get() *Conf {
|
|
return &s.config
|
|
}
|
|
|
|
// Save writes the in-memory configuration to the config file.
|
|
func (s *Service) Save() error {
|
|
err := s.config.Write(configFilename)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// Do the logging here, as our caller doesn't know `configFilename``.
|
|
log.Info().Str("filename", configFilename).Msg("configuration file written")
|
|
return nil
|
|
}
|
|
|
|
// Expose some functions on Conf here, for easier mocking of functionality via interfaces.
|
|
//
|
|
func (s *Service) ExpandVariables(valueToExpand string, audience VariableAudience, platform VariablePlatform) string {
|
|
return s.config.ExpandVariables(valueToExpand, audience, platform)
|
|
}
|
|
func (s *Service) ResolveVariables(audience VariableAudience, platform VariablePlatform) map[string]ResolvedVariable {
|
|
return s.config.ResolveVariables(audience, platform)
|
|
}
|
|
func (s *Service) EffectiveStoragePath() string {
|
|
return s.config.EffectiveStoragePath()
|
|
}
|