add rm
This commit is contained in:
parent
40676450c5
commit
83368e8c2b
@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"strconv"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
@ -32,8 +32,11 @@ and usage of using your command. For example:
|
|||||||
Cobra is a CLI library for Go that empowers applications.
|
Cobra is a CLI library for Go that empowers applications.
|
||||||
This application is a tool to generate the needed files
|
This application is a tool to generate the needed files
|
||||||
to quickly create a Cobra application.`,
|
to quickly create a Cobra application.`,
|
||||||
|
Args: cobra.MinimumNArgs(1),
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
fmt.Println("rm called")
|
id, err := strconv.ParseUint(args[0], 10, 0)
|
||||||
|
errPanic(err, "failed to parse uint")
|
||||||
|
deleteTodo(id)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ func createTodo(desc string, date string) {
|
|||||||
db.Create(&t)
|
db.Create(&t)
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateTodo(id uint, new Todo) {
|
func updateTodo(id uint64, new Todo) {
|
||||||
db := openDB()
|
db := openDB()
|
||||||
var t Todo
|
var t Todo
|
||||||
res := db.First(&t, id)
|
res := db.First(&t, id)
|
||||||
@ -64,7 +64,7 @@ func updateTodo(id uint, new Todo) {
|
|||||||
db.Model(&t).Updates(new)
|
db.Model(&t).Updates(new)
|
||||||
}
|
}
|
||||||
|
|
||||||
func deleteTodo(id uint) {
|
func deleteTodo(id uint64) {
|
||||||
db := openDB()
|
db := openDB()
|
||||||
db.Delete(&Todo{}, id)
|
db.Delete(&Todo{}, id)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user