refactor: replace explicit fields with tag-based property system
This commit is contained in:
19
cmd/init.go
19
cmd/init.go
@@ -11,28 +11,23 @@ import (
|
||||
)
|
||||
|
||||
var initCmd = &cobra.Command{
|
||||
Use: "init [path]",
|
||||
Short: "Initialize a new database",
|
||||
Args: cobra.MaximumNArgs(1),
|
||||
Use: "init [path]", Short: "Initialize a new database", Args: cobra.MaximumNArgs(1),
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
path := "."
|
||||
p := "."
|
||||
if len(args) > 0 {
|
||||
path = args[0]
|
||||
p = args[0]
|
||||
}
|
||||
dbPath := filepath.Join(path, ".ax.db")
|
||||
dbPath := filepath.Join(p, ".ax.db")
|
||||
if _, err := os.Stat(dbPath); err == nil {
|
||||
fmt.Fprintln(os.Stderr, "database already exists:", dbPath)
|
||||
os.Exit(1)
|
||||
}
|
||||
err := db.Init(dbPath)
|
||||
if err != nil {
|
||||
if err := db.Init(dbPath); err != nil {
|
||||
fmt.Fprintln(os.Stderr, "failed to initialize:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
output.PrintCreated(cmd.OutOrStdout(), dbPath)
|
||||
output.PrintAction(cmd.OutOrStdout(), "Created", dbPath, false)
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(initCmd)
|
||||
}
|
||||
func init() { rootCmd.AddCommand(initCmd) }
|
||||
|
||||
Reference in New Issue
Block a user