2022-09-12 22:12:02 +02:00
package commands
import (
"bytes"
"encoding/json"
"net/http"
"github.com/spf13/cobra"
)
func CreateKrakenProcessCmd ( ) * cobra . Command {
2022-09-18 16:33:10 +02:00
var (
actionsRepo string
branch string
path string
)
2022-09-12 22:12:02 +02:00
cmd := & cobra . Command {
Use : "process" ,
2022-09-18 16:33:10 +02:00
RunE : func ( cmd * cobra . Command , args [ ] string ) error {
if err := cmd . ParseFlags ( args ) ; err != nil {
return err
}
2022-09-12 22:12:02 +02:00
client := http . Client { }
var buf bytes . Buffer
err := json . NewEncoder ( & buf ) .
Encode ( struct {
2022-09-13 22:54:49 +02:00
Repository string ` json:"repository" `
Branch string ` json:"branch" `
Path string ` json:"path" `
2022-09-12 22:12:02 +02:00
} {
2022-09-18 16:33:10 +02:00
Repository : actionsRepo ,
Branch : branch ,
Path : path ,
2022-09-13 22:54:49 +02:00
} )
2022-09-12 22:12:02 +02:00
if err != nil {
panic ( err )
}
req , err := http . NewRequestWithContext (
cmd . Context ( ) ,
http . MethodPost ,
"http://localhost:3000/commands/processRepos" ,
& buf ,
)
if err != nil {
panic ( err )
}
resp , err := client . Do ( req )
if err != nil {
panic ( err )
}
if resp . StatusCode >= 300 {
panic ( resp . Status )
}
2022-09-18 16:33:10 +02:00
return nil
2022-09-12 22:12:02 +02:00
} ,
}
2022-09-18 16:33:10 +02:00
pf := cmd . PersistentFlags ( )
pf . StringVar ( & actionsRepo , "actions-repo" , "" , "actions repo is the location of your actions, not where to apply the actions themselves, that should be self contained" )
cmd . MarkPersistentFlagRequired ( "actions-repo" )
pf . StringVar ( & branch , "branch" , "main" , "which branch to look for actions in, will default to main" )
pf . StringVar ( & path , "path" , "" , "the location of the path inside the repository" )
cmd . MarkPersistentFlagRequired ( "path" )
2022-09-12 22:12:02 +02:00
return cmd
}