feat: introduce an option for keeping existing folder structure of dump folder (#12)
This commit is contained in:
parent
e2b5cc7e60
commit
617007edd1
@ -59,6 +59,7 @@ func init() {
|
|||||||
rootCmd.PersistentFlags().String("key-ext", ".key", "The file extension of the generated private keys.")
|
rootCmd.PersistentFlags().String("key-ext", ".key", "The file extension of the generated private keys.")
|
||||||
rootCmd.PersistentFlags().String("key-name", "privatekey", "The file name (without extension) of the generated private keys.")
|
rootCmd.PersistentFlags().String("key-name", "privatekey", "The file name (without extension) of the generated private keys.")
|
||||||
rootCmd.PersistentFlags().Bool("domain-subdir", false, "Use domain as sub-directory.")
|
rootCmd.PersistentFlags().Bool("domain-subdir", false, "Use domain as sub-directory.")
|
||||||
|
rootCmd.PersistentFlags().Bool("clean", true, "Clean destination folder before dumping content.")
|
||||||
}
|
}
|
||||||
|
|
||||||
// initConfig reads in config file and ENV variables if set.
|
// initConfig reads in config file and ENV variables if set.
|
||||||
@ -93,6 +94,11 @@ func getBaseConfig(cmd *cobra.Command) (*dumper.BaseConfig, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
clean, err := strconv.ParseBool(cmd.Flag("clean").Value.String())
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
return &dumper.BaseConfig{
|
return &dumper.BaseConfig{
|
||||||
DumpPath: cmd.Flag("dest").Value.String(),
|
DumpPath: cmd.Flag("dest").Value.String(),
|
||||||
CrtInfo: dumper.FileInfo{
|
CrtInfo: dumper.FileInfo{
|
||||||
@ -104,6 +110,7 @@ func getBaseConfig(cmd *cobra.Command) (*dumper.BaseConfig, error) {
|
|||||||
Ext: cmd.Flag("key-ext").Value.String(),
|
Ext: cmd.Flag("key-ext").Value.String(),
|
||||||
},
|
},
|
||||||
DomainSubDir: subDir,
|
DomainSubDir: subDir,
|
||||||
|
Clean: clean,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -6,4 +6,5 @@ type BaseConfig struct {
|
|||||||
CrtInfo FileInfo
|
CrtInfo FileInfo
|
||||||
KeyInfo FileInfo
|
KeyInfo FileInfo
|
||||||
DomainSubDir bool
|
DomainSubDir bool
|
||||||
|
Clean bool
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,8 +22,11 @@ type FileInfo struct {
|
|||||||
|
|
||||||
// Dump Dumps data to certificates.
|
// Dump Dumps data to certificates.
|
||||||
func Dump(data *StoredData, baseConfig *BaseConfig) error {
|
func Dump(data *StoredData, baseConfig *BaseConfig) error {
|
||||||
if err := os.RemoveAll(baseConfig.DumpPath); err != nil {
|
|
||||||
return err
|
if baseConfig.Clean {
|
||||||
|
if err := os.RemoveAll(baseConfig.DumpPath); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !baseConfig.DomainSubDir {
|
if !baseConfig.DomainSubDir {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user