diff --git a/README.md b/README.md index b1c9dce38dbd44ae7683cf29a680df00cdfa7d66..1d2462784770693df72408010db912f36d77fe77 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,15 @@ ds init ### Add a new table ```bash -ds add table "Table Name" +ds add +``` + +```bash +ds add "Table Name" +``` + +```bash +ds add users --model '{"fields":[{"name":"id","type":"INT","primary_key":true,"auto_increment":true,"not_null":true},{"name":"name","type":"VARCHAR(255)","unique":true,"not_null":true},{"name":"email","type":"VARCHAR(255)","unique":true,"not_null":true},{"name":"created_at","type":"DATETIME","not_null":true,"default_value":"CURRENT_TIMESTAMP"}]}' ``` ## Contributing diff --git a/commands/add.go b/commands/add.go index c8b5c29b7d8ff086a5159a90dcfcafd5cacb427c..71c8c642b8dca695b9ee2f150bb646dd54b68405 100644 --- a/commands/add.go +++ b/commands/add.go @@ -299,18 +299,18 @@ func promptForTableModel() TableModel { utils.PromptIfEmpty(&field.Name, "Enter field name: ") field.Type = promptForFieldType() - field.PrimaryKey = utils.PromptForBool("Is this a primary key? (y/n): ") + field.PrimaryKey = utils.PromptForBool("Is this a primary key? (y/n): ") // TODO: use SelectMenu if !field.PrimaryKey { utils.PromptIfEmpty(&field.ForeignKey, "Enter foreign key (leave empty if not applicable): ") } - field.Unique = utils.PromptForBool("Is this field unique? (y/n): ") - field.NotNull = utils.PromptForBool("Is this field not null? (y/n): ") - field.AutoIncrement = utils.PromptForBool("Is this field auto-increment? (y/n): ") + field.Unique = utils.PromptForBool("Is this field unique? (y/n): ") // TODO: use SelectMenu + field.NotNull = utils.PromptForBool("Is this field not null? (y/n): ") // TODO: use SelectMenu + field.AutoIncrement = utils.PromptForBool("Is this field auto-increment? (y/n): ") // TODO: use SelectMenu field.DefaultValue = utils.PromptForString("Enter default value (leave empty if not applicable): ") fields = append(fields, field) - if !utils.PromptForBool("Do you want to add another field? (y/n): ") { + if !utils.PromptForBool("Do you want to add another field? (y/n): ") { // TODO: use SelectMenu break } } diff --git a/main.go b/main.go index eeb075721ed681adbbf0ab3c3bcb93ba756936a9..c5804594c519bfa8fb9c44d70d860a12f28bc1ba 100644 --- a/main.go +++ b/main.go @@ -36,13 +36,19 @@ func main() { case "add": var tableName, model string args := os.Args[2:] - for i, arg := range args { + for i := 0; i < len(args); i++ { + arg := args[i] if arg == "--model" && i+1 < len(args) { model = args[i+1] + i++ // Skip the next argument since it's the model value } else if !strings.HasPrefix(arg, "--") { tableName = arg } } + if tableName == "" { + fmt.Println("Usage: ds add <tablename> [--model <json_model>]") + return + } commands.Add(tableName, model) case "version": commands.Version(version)