forked from aksdb/CalAnonSync
Added command to create empty settings
This commit is contained in:
parent
4d93b99cad
commit
8d8cc94213
|
@ -131,7 +131,13 @@ over-the-shoulder "attacks".`,
|
||||||
Run: runSettingsDecryption,
|
Run: runSettingsDecryption,
|
||||||
}
|
}
|
||||||
|
|
||||||
settingsCmd.AddCommand(encryptCmd, decryptCmd)
|
initCmd := &cobra.Command{
|
||||||
|
Use: "init",
|
||||||
|
Short: "Initialize an empty but valid settings file.",
|
||||||
|
Run: runSettingsInit,
|
||||||
|
}
|
||||||
|
|
||||||
|
settingsCmd.AddCommand(encryptCmd, decryptCmd, initCmd)
|
||||||
return settingsCmd
|
return settingsCmd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -225,6 +231,30 @@ func runSettingsDecryption(cmd *cobra.Command, args []string) {
|
||||||
log.Println("Settings decrypted")
|
log.Println("Settings decrypted")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func runSettingsInit(cmd *cobra.Command, args []string) {
|
||||||
|
if _, err := os.Stat(settingsName); err == nil || os.IsExist(err) {
|
||||||
|
log.Fatalln("You already have a settings file! Remove that first if you really want a new blank one!")
|
||||||
|
}
|
||||||
|
|
||||||
|
s := Settings{}
|
||||||
|
s.Anonymize.Title = &StringAnonSettings{ReplaceWith: "Replacement", Whitelist: []string{}}
|
||||||
|
|
||||||
|
// Rewrite the settings file.
|
||||||
|
f, err := os.OpenFile(settingsName, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0600)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Could not rewrite settings: %s\n", err)
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
e := json.NewEncoder(f)
|
||||||
|
e.SetIndent("", " ")
|
||||||
|
err = e.Encode(&s)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Println("Blank settings have been created.")
|
||||||
|
}
|
||||||
|
|
||||||
// Apply the anonymization rule to the given string, returning the
|
// Apply the anonymization rule to the given string, returning the
|
||||||
// anonymized version.
|
// anonymized version.
|
||||||
// If the anonymization is nil or empty, the original string will
|
// If the anonymization is nil or empty, the original string will
|
||||||
|
|
Loading…
Reference in New Issue