forked from Gitlink/gitlink-cli
52 lines
1.2 KiB
Go
52 lines
1.2 KiB
Go
package attachment
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/gitlink-org/gitlink-cli/shortcuts/common"
|
|
)
|
|
|
|
func Shortcuts() []*common.Shortcut {
|
|
return []*common.Shortcut{
|
|
{
|
|
Name: "upload",
|
|
Description: "Upload a file attachment",
|
|
Flags: []common.Flag{
|
|
{Name: "file", Short: "f", Usage: "Path to the file to upload", Required: true},
|
|
},
|
|
Run: func(ctx *common.RuntimeContext) error {
|
|
file, err := ctx.RequireArg("file")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
payload := map[string]interface{}{
|
|
"file": file,
|
|
}
|
|
env, err := ctx.CallAPI("POST", "/attachments", payload)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return ctx.Output(env)
|
|
},
|
|
},
|
|
{
|
|
Name: "delete",
|
|
Description: "Delete a file attachment by UUID",
|
|
Flags: []common.Flag{
|
|
{Name: "uuid", Short: "u", Usage: "Attachment UUID to delete", Required: true},
|
|
},
|
|
Run: func(ctx *common.RuntimeContext) error {
|
|
uuid, err := ctx.RequireArg("uuid")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
env, err := ctx.CallAPI("DELETE", fmt.Sprintf("/attachments/%s", uuid), nil)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return ctx.Output(env)
|
|
},
|
|
},
|
|
}
|
|
}
|