Skip to content

Commit

Permalink
added --db-only parameter to note init
Browse files Browse the repository at this point in the history
  • Loading branch information
bdazl committed Oct 27, 2024
1 parent 2dc1bf4 commit f07ab29
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
25 changes: 13 additions & 12 deletions cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,28 +43,29 @@ func noteInit(cmd *cobra.Command, args []string) {
// the option from the config file.
viper.Set("db", dbF)

mkdir(filepath.Dir(configPathArg))
mkdir(filepath.Dir(dbF))

if !forceArg && exists(configPathArg) {
fmt.Fprintln(os.Stderr, "Config file already exists")
forceInform = true
} else {
fmt.Printf("Writing config file: %v\n", configPathArg)
err := viper.WriteConfig()
if err != nil {
quitError("writing config", err)
if !dbOnlyArg {
if !forceArg && exists(configPathArg) {
fmt.Fprintln(os.Stderr, "Config file already exists")
forceInform = true
} else {
mkdir(filepath.Dir(configPathArg))
err := viper.WriteConfig()
if err != nil {
quitError("writing config", err)
}
fmt.Printf("Wrote config file: %v\n", configPathArg)
}
}

if !forceArg && exists(dbF) {
fmt.Fprintln(os.Stderr, "Storage file already exists")
forceInform = true
} else {
fmt.Printf("Create initial db: %v\n", dbF)
mkdir(filepath.Dir(dbF))
if _, err := db.CreateDb(dbF); err != nil {
quitError("creating db", err)
}
fmt.Printf("Created db: %v\n", dbF)
}

if forceInform {
Expand Down
4 changes: 3 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,8 @@ Files will only be imported once (per run), no checks for duplicate notes are ma
storagePathArg string

// Init argument
forceArg bool
dbOnlyArg bool
forceArg bool

// Add arguments
fileArg string
Expand Down Expand Up @@ -364,6 +365,7 @@ func init() {
rootFlags.AddFlagSet(selectFlagSet)

initFlags := initCmd.Flags()
initFlags.BoolVar(&dbOnlyArg, "db-only", false, "only initialize a database file")
initFlags.BoolVar(&forceArg, "force", false, "determines if existing files will be overwritten")

addFlags := addCmd.Flags()
Expand Down

0 comments on commit f07ab29

Please sign in to comment.