Skip to content

Commit 67b2394

Browse files
chore: fix cj
1 parent 7a9f6bc commit 67b2394

5 files changed

Lines changed: 12 additions & 12 deletions

File tree

cmd/cronjobs/create.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/NodeOps-app/createos-cli/internal/api"
1212
"github.com/NodeOps-app/createos-cli/internal/cmdutil"
1313
"github.com/NodeOps-app/createos-cli/internal/terminal"
14+
"github.com/NodeOps-app/createos-cli/internal/utils"
1415
)
1516

1617
func newCronjobsCreateCommand() *cli.Command {
@@ -130,6 +131,7 @@ Examples:
130131
if err != nil {
131132
return fmt.Errorf("could not read path: %w", err)
132133
}
134+
path = pterm.RemoveColorFromString(path)
133135
}
134136
if method == "GET" {
135137
methods := []string{"GET", "POST", "PUT", "DELETE", "PATCH", "HEAD"}
@@ -179,11 +181,7 @@ Examples:
179181
Headers: headers,
180182
}
181183
if bodyStr != "" {
182-
if !json.Valid([]byte(bodyStr)) {
183-
return fmt.Errorf("body must be valid JSON (e.g. '{\"key\":\"value\"}')")
184-
}
185-
raw := json.RawMessage(bodyStr)
186-
settings.Body = &raw
184+
settings.Body = utils.Ptr(bodyStr)
187185
}
188186
settingsJSON, err := json.Marshal(settings)
189187
if err != nil {

cmd/cronjobs/get.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func newCronjobsGetCommand() *cli.Command {
8383
}
8484
if s.Body != nil {
8585
label.Print("Body: ")
86-
fmt.Println(string(*s.Body))
86+
fmt.Println(*s.Body)
8787
}
8888
if s.TimeoutInSeconds != nil {
8989
label.Print("Timeout (s): ")

cmd/cronjobs/update.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ Examples:
113113
if err != nil {
114114
return fmt.Errorf("could not read path: %w", err)
115115
}
116+
path = pterm.RemoveColorFromString(path)
116117
}
117118
if method == "" {
118119
defaultMethod := "GET"
@@ -168,11 +169,7 @@ Examples:
168169
Body: currentSettings.Body,
169170
}
170171
if bodyStr != "" {
171-
if !json.Valid([]byte(bodyStr)) {
172-
return fmt.Errorf("body must be valid JSON (e.g. '{\"key\":\"value\"}')")
173-
}
174-
raw := json.RawMessage(bodyStr)
175-
settings.Body = &raw
172+
settings.Body = &bodyStr
176173
}
177174
settingsJSON, err := json.Marshal(settings)
178175
if err != nil {

internal/api/cronjobs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ type HTTPCronjobSettings struct {
4949
Path string `json:"path"`
5050
Method string `json:"method"`
5151
Headers map[string]string `json:"headers,omitempty"`
52-
Body *json.RawMessage `json:"body,omitempty"`
52+
Body *string `json:"body,omitempty"`
5353
TimeoutInSeconds *int `json:"timeoutInSeconds,omitempty"`
5454
}
5555

internal/utils/ptr.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package utils
2+
3+
func Ptr[T any](v T) *T {
4+
return &v
5+
}

0 commit comments

Comments
 (0)