Skip to content

Commit

Permalink
Add db-path flag
Browse files Browse the repository at this point in the history
  • Loading branch information
mpppk committed Jul 18, 2019
1 parent 6b8f080 commit 4053986
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 5 additions & 1 deletion cmd/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ var genCmd = &cobra.Command{
words = append(words, record[colIndex])
}

boltStorage, err := lib.NewBoltStorage("test.db")
boltStorage, err := lib.NewBoltStorage(config.DBPath)
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -114,6 +114,10 @@ func init() {
if err := viper.BindPFlag(flagKeys.File, genCmd.Flags().Lookup(flagKeys.File)); err != nil {
panic(err)
}
genCmd.Flags().StringP(flagKeys.DBPath, "d", "", "DB file path")
if err := viper.BindPFlag(flagKeys.DBPath, genCmd.Flags().Lookup(flagKeys.DBPath)); err != nil {
panic(err)
}
genCmd.Flags().StringP(flagKeys.ColName, "c", "0", "Target column name or index")
if err := viper.BindPFlag(flagKeys.ColName, genCmd.Flags().Lookup(flagKeys.ColName)); err != nil {
panic(err)
Expand Down
4 changes: 4 additions & 0 deletions gen/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ var NoneOutputMode OutputMode = "none"
type OutputMode string
type FlagKeys struct {
File string
DBPath string
ColName string
MinParallelDepth string
MaxLogDepth string
Expand All @@ -28,6 +29,7 @@ type FlagKeys struct {
func NewFlagKeys() *FlagKeys {
return &FlagKeys{
File: "file",
DBPath: "db-path",
ColName: "col",
MinParallelDepth: "min-p-depth",
MaxLogDepth: "max-log-depth",
Expand All @@ -39,6 +41,7 @@ func NewFlagKeys() *FlagKeys {

type Config struct {
FilePath string
DBPath string
ColName string
DepthOptions *lib.DepthOptions
OutputMode OutputMode
Expand All @@ -48,6 +51,7 @@ func NewConfigFromViper() *Config {
flagKeys := NewFlagKeys()
return &Config{
FilePath: viper.GetString(flagKeys.File),
DBPath: viper.GetString(flagKeys.DBPath),
ColName: viper.GetString(flagKeys.ColName),
DepthOptions: &lib.DepthOptions{
MinParallel: viper.GetInt(flagKeys.MinParallelDepth),
Expand Down

0 comments on commit 4053986

Please sign in to comment.