Adding Initial action (#1)
Co-authored-by: kjuulh <contact@kjuulh.io> Reviewed-on: kjuulh/kraken#1
This commit is contained in:
48
cmd/kraken/commands/process.go
Normal file
48
cmd/kraken/commands/process.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func CreateKrakenProcessCmd() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "process",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
client := http.Client{}
|
||||
|
||||
var buf bytes.Buffer
|
||||
err := json.NewEncoder(&buf).
|
||||
Encode(struct {
|
||||
RepositoryUrls []string `json:"repositoryUrls"`
|
||||
}{
|
||||
RepositoryUrls: []string{"git@git.front.kjuulh.io:kjuulh/kraken.git"}})
|
||||
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)
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
return cmd
|
||||
}
|
@@ -4,19 +4,11 @@ import "github.com/spf13/cobra"
|
||||
|
||||
func CreateKrakenCmd() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "krakenserver",
|
||||
Short: "A brief description of your application",
|
||||
Long: `A longer description that spans multiple lines and likely contains
|
||||
examples and usage of using your application. For example:
|
||||
|
||||
Cobra is a CLI library for Go that empowers applications.
|
||||
This application is a tool to generate the needed files
|
||||
to quickly create a Cobra application.`,
|
||||
// Uncomment the following line if your bare application
|
||||
// has an action associated with it:
|
||||
Use: "kraken",
|
||||
// Run: func(cmd *cobra.Command, args []string) { },
|
||||
}
|
||||
cmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
|
||||
|
||||
cmd.AddCommand(CreateKrakenProcessCmd())
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
@@ -3,7 +3,7 @@ package main
|
||||
import (
|
||||
"os"
|
||||
|
||||
"git.front.kjuulh.io/kjuulh/kraken/cmd/server/commands"
|
||||
"git.front.kjuulh.io/kjuulh/kraken/cmd/kraken/commands"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -11,7 +11,7 @@ func main() {
|
||||
}
|
||||
|
||||
func Execute() {
|
||||
err := commands.CreateServerCmd().Execute()
|
||||
err := commands.CreateKrakenCmd().Execute()
|
||||
if err != nil {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
Reference in New Issue
Block a user