2018-05-18 06:08:34 +00:00
|
|
|
package cli
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2018-05-30 23:28:31 +00:00
|
|
|
"github.com/strongdm/comply/internal/config"
|
2018-05-18 06:08:34 +00:00
|
|
|
"github.com/strongdm/comply/internal/model"
|
|
|
|
"github.com/urfave/cli"
|
|
|
|
)
|
|
|
|
|
|
|
|
var procedureCommand = cli.Command{
|
|
|
|
Name: "procedure",
|
|
|
|
ShortName: "proc",
|
|
|
|
Usage: "create ticket by procedure ID",
|
|
|
|
ArgsUsage: "procedureID",
|
|
|
|
Action: procedureAction,
|
2018-06-08 05:23:51 +00:00
|
|
|
Before: beforeAll(projectMustExist, ticketingMustBeConfigured),
|
2018-05-18 06:08:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func procedureAction(c *cli.Context) error {
|
|
|
|
procedures, err := model.ReadProcedures()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.NArg() != 1 {
|
|
|
|
return cli.NewExitError("provide a procedure ID", 1)
|
|
|
|
}
|
|
|
|
|
|
|
|
procedureID := c.Args().First()
|
|
|
|
|
2018-05-30 23:28:31 +00:00
|
|
|
ts, err := config.Config().TicketSystem()
|
|
|
|
if err != nil {
|
|
|
|
return cli.NewExitError("error in ticket system configuration", 1)
|
|
|
|
}
|
|
|
|
|
|
|
|
tp := model.GetPlugin(model.TicketSystem(ts))
|
|
|
|
|
2018-05-18 06:08:34 +00:00
|
|
|
for _, procedure := range procedures {
|
|
|
|
if procedure.ID == procedureID {
|
2019-08-11 10:24:27 +00:00
|
|
|
err = tp.Create(procedure.NewTicket(), procedure.Labels())
|
2018-05-30 23:28:31 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-05-18 06:08:34 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return cli.NewExitError(fmt.Sprintf("unknown procedure ID: %s", procedureID), 1)
|
|
|
|
}
|