Skip to content

Commit

Permalink
documentationf for Save command
Browse files Browse the repository at this point in the history
  • Loading branch information
weynsee committed May 18, 2015
1 parent 428bae5 commit 0be6d35
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions cli/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,16 @@ type Config struct {
Encoding string `json:"encoding,omitempty"`
}

// Config stores locale specific configuration options
type LocaleConfig struct {
Config
format
}

// NewConfig returns a Config instance. Its properties will be
// populated from the file found in the path argument
// (assumed to be in a certain JSON format), and some properties
// will have default values assigned.
func NewConfig(path string) (*Config, error) {
config := new(Config)
config.path = path
Expand All @@ -51,10 +56,12 @@ func NewConfig(path string) (*Config, error) {
return config, nil
}

// ForLocale returns a LocaleConfig for the given Locale.
func (c *Config) ForLocale(l *phrase.Locale) *LocaleConfig {
return newLocaleConfig(c, l)
}

// Valid validates the current config to check whether all values are valid.
func (c *Config) Valid() error {
_, found := formats[c.Format]
if !found {
Expand All @@ -81,6 +88,8 @@ func newLocaleConfig(c *Config, l *phrase.Locale) *LocaleConfig {
return lc
}

// Save saves current values of the properties of the Config
// instance to disk.
func (c *Config) Save() error {
f, err := os.OpenFile(c.path, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0660)
if err != nil {
Expand Down

0 comments on commit 0be6d35

Please sign in to comment.