Skip to content

Commit cdfe7ed

Browse files
chore: consistency for args and flags (#18)
* chore: consistancy for args and flags * chore: fix lint * chore: fix file namings * chore: fix cj * chore: fix lint * chore: fix lint
1 parent 86a92f9 commit cdfe7ed

66 files changed

Lines changed: 1122 additions & 924 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 134 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,11 @@ createos --help
7878

7979
### Projects
8080

81-
| Command | Description |
82-
| -------------------------- | ---------------- |
83-
| `createos projects list` | List all projects |
81+
| Command | Description |
82+
| -------------------------- | ------------------- |
83+
| `createos projects list` | List all projects |
8484
| `createos projects get` | Get project details |
85-
| `createos projects delete` | Delete a project |
85+
| `createos projects delete` | Delete a project |
8686

8787
### Deployments
8888

@@ -93,7 +93,7 @@ createos --help
9393
| `createos deployments build-logs` | Stream build logs for a deployment |
9494
| `createos deployments retrigger` | Retrigger a deployment |
9595
| `createos deployments wakeup` | Wake up a sleeping deployment |
96-
| `createos deployments cancel` | Cancel a deployment |
96+
| `createos deployments cancel` | Cancel a running deployment |
9797

9898
### Environments
9999

@@ -104,30 +104,52 @@ createos --help
104104

105105
### Environment Variables
106106

107-
| Command | Description |
108-
| ---------------------- | ------------------------------------------------- |
109-
| `createos env list` | List environment variables for a project |
110-
| `createos env set` | Set one or more environment variables |
111-
| `createos env rm` | Remove an environment variable |
112-
| `createos env pull` | Download environment variables to a local `.env` file |
113-
| `createos env push` | Upload environment variables from a local `.env` file |
107+
| Command | Description |
108+
| ------------------- | ----------------------------------------------------- |
109+
| `createos env list` | List environment variables for a project |
110+
| `createos env set` | Set one or more environment variables |
111+
| `createos env rm` | Remove an environment variable |
112+
| `createos env pull` | Download environment variables to a local `.env` file |
113+
| `createos env push` | Upload environment variables from a local `.env` file |
114114

115115
### Domains
116116

117-
| Command | Description |
118-
| -------------------------- | --------------------------------- |
119-
| `createos domains list` | List custom domains for a project |
120-
| `createos domains add` | Add a custom domain |
121-
| `createos domains verify` | Check DNS propagation and wait for verification |
122-
| `createos domains delete` | Remove a custom domain |
117+
| Command | Description |
118+
| ------------------------- | ----------------------------------------------- |
119+
| `createos domains list` | List custom domains for a project |
120+
| `createos domains create` | Create a custom domain for a project |
121+
| `createos domains verify` | Check DNS propagation and wait for verification |
122+
| `createos domains delete` | Delete a custom domain |
123+
124+
### Cron Jobs
125+
126+
| Command | Description |
127+
| -------------------------------- | -------------------------------------- |
128+
| `createos cronjobs list` | List cron jobs for a project |
129+
| `createos cronjobs create` | Create a new HTTP cron job |
130+
| `createos cronjobs get` | Show details for a cron job (including path, method, headers, body) |
131+
| `createos cronjobs update` | Update a cron job's name, schedule, or HTTP settings |
132+
| `createos cronjobs suspend` | Pause a cron job |
133+
| `createos cronjobs unsuspend` | Resume a suspended cron job |
134+
| `createos cronjobs activities` | Show recent execution history |
135+
| `createos cronjobs delete` | Delete a cron job |
136+
137+
**HTTP settings flags** (for `create` and `update`):
138+
139+
| Flag | Description |
140+
| ---- | ----------- |
141+
| `--path` | HTTP path to call, must start with `/` |
142+
| `--method` | HTTP method: `GET`, `POST`, `PUT`, `DELETE`, `PATCH`, `HEAD` |
143+
| `--header` | Header in `Key=Value` format, repeatable |
144+
| `--body` | JSON body to send with the request (only for POST, PUT, PATCH) |
123145

124146
### Templates
125147

126-
| Command | Description |
127-
| -------------------------- | --------------------------------------------- |
128-
| `createos templates list` | Browse available project templates |
129-
| `createos templates info` | Show details about a template |
130-
| `createos templates use` | Download and scaffold a project from a template |
148+
| Command | Description |
149+
| ------------------------- | ------------------------------------------------ |
150+
| `createos templates list` | Browse available project templates |
151+
| `createos templates info` | Show details about a template |
152+
| `createos templates use` | Download and scaffold a project from a template |
131153

132154
### VMs
133155

@@ -150,20 +172,21 @@ createos --help
150172

151173
### Quick Actions
152174

153-
| Command | Description |
154-
| ----------------- | ------------------------------------------------- |
155-
| `createos init` | Link the current directory to a CreateOS project |
156-
| `createos status` | Show a project's health and deployment status |
157-
| `createos open` | Open a project's live URL in your browser |
158-
| `createos scale` | Adjust replicas and resources for an environment |
175+
| Command | Description |
176+
| ----------------- | ------------------------------------------------ |
177+
| `createos init` | Link the current directory to a CreateOS project |
178+
| `createos status` | Show a project's health and deployment status |
179+
| `createos open` | Open a project's live URL in your browser |
180+
| `createos scale` | Adjust replicas and resources for an environment |
159181

160182
### OAuth Clients
161183

162-
| Command | Description |
163-
| -------------------------------------- | ------------------------------------- |
164-
| `createos oauth-clients list` | List your OAuth clients |
165-
| `createos oauth-clients create` | Create a new OAuth client |
166-
| `createos oauth-clients instructions` | Show setup instructions for a client |
184+
| Command | Description |
185+
| ------------------------------------- | ------------------------------------ |
186+
| `createos oauth-clients list` | List your OAuth clients |
187+
| `createos oauth-clients create` | Create a new OAuth client |
188+
| `createos oauth-clients instructions` | Show setup instructions for a client |
189+
| `createos oauth-clients delete` | Delete an OAuth client |
167190

168191
### Me
169192

@@ -182,57 +205,114 @@ createos --help
182205

183206
## Non-interactive / CI usage
184207

185-
All commands that would normally show an interactive prompt accept flags instead:
208+
All commands accept flags so they work in CI and non-interactive environments. Destructive commands require `--force` to skip the confirmation prompt.
186209

187210
```bash
188-
# OAuth clients
189-
createos oauth-clients instructions --client <client-id>
190-
createos oauth-clients create \
191-
--name "My App" \
192-
--redirect-uri https://myapp.com/callback \
193-
--app-url https://myapp.com \
194-
--policy-url https://myapp.com/privacy \
195-
--tos-url https://myapp.com/tos \
196-
--logo-url https://myapp.com/logo.png
197-
198211
# Projects
199212
createos projects get --project <id>
213+
createos projects delete --project <id> --force
200214

201215
# Deployments
216+
createos deployments list --project <id>
202217
createos deployments logs --project <id> --deployment <id>
218+
createos deployments build-logs --project <id> --deployment <id>
203219
createos deployments retrigger --project <id> --deployment <id>
220+
createos deployments wakeup --project <id> --deployment <id>
221+
createos deployments cancel --project <id> --deployment <id> --force
204222

205223
# Environments
206-
createos environments delete --project <id> --environment <id>
224+
createos environments list --project <id>
225+
createos environments delete --project <id> --environment <id> --force
207226

208227
# Environment variables
209228
createos env list --project <id> --environment <id>
210229
createos env set KEY=value --project <id> --environment <id>
230+
createos env rm KEY --project <id> --environment <id>
211231
createos env pull --project <id> --environment <id> --force
232+
createos env push --project <id> --environment <id> --force
212233

213234
# Domains
214-
createos domains add example.com --project <id>
235+
createos domains list --project <id>
236+
createos domains create --project <id> --name example.com
215237
createos domains verify --project <id> --domain <id> --no-wait
216-
createos domains delete --project <id> --domain <id>
238+
createos domains delete --project <id> --domain <id> --force
239+
240+
# Cron jobs
241+
createos cronjobs list --project <id>
242+
243+
# Simple GET cron job
244+
createos cronjobs create --project <id> --environment <id> \
245+
--name "Cleanup job" --schedule "0 * * * *" \
246+
--path /api/cleanup --method GET
247+
248+
# POST cron job with headers and JSON body
249+
createos cronjobs create --project <id> --environment <id> \
250+
--name "Webhook" --schedule "*/5 * * * *" \
251+
--path /api/hook --method POST \
252+
--header "Authorization=Bearer token" --header "X-Source=cron" \
253+
--body '{"event":"tick"}'
254+
255+
# Update HTTP settings (headers and body preserved if omitted)
256+
createos cronjobs update --project <id> --cronjob <id> \
257+
--path /api/hook --method POST \
258+
--header "Authorization=Bearer token" --body '{"event":"tick"}'
259+
260+
createos cronjobs get --project <id> --cronjob <id>
261+
createos cronjobs delete --project <id> --cronjob <id> --force
217262

218263
# Templates
219264
createos templates use --template <id> --yes
220265

221266
# VMs
267+
createos vms list
222268
createos vms get --vm <id>
269+
createos vms deploy --zone nyc3 --size 1 --name "my-vm" --ssh-key "ssh-ed25519 ..."
223270
createos vms reboot --vm <id> --force
224271
createos vms terminate --vm <id> --force
225272
createos vms resize --vm <id> --size 1
226-
createos vms deploy --zone nyc3 --size 1
273+
274+
# OAuth clients
275+
createos oauth-clients list
276+
createos oauth-clients create \
277+
--name "My App" \
278+
--redirect-uri https://myapp.com/callback \
279+
--app-url https://myapp.com \
280+
--policy-url https://myapp.com/privacy \
281+
--tos-url https://myapp.com/tos \
282+
--logo-url https://myapp.com/logo.png
283+
createos oauth-clients instructions --client <id>
284+
createos oauth-clients delete --client <id> --force
285+
286+
# Me
287+
createos me oauth-consents list
288+
createos me oauth-consents revoke --client <id> --force
289+
```
290+
291+
## JSON output and piping
292+
293+
All list and get commands output JSON automatically when stdout is a pipe, so `| jq` works without any flags:
294+
295+
```bash
296+
createos projects list | jq '.[].id'
297+
createos deployments list --project <id> | jq '.[] | select(.status == "running")'
298+
createos cronjobs list --project <id> | jq '.[] | {id, name, schedule}'
299+
createos vms list | jq '.[].extra.ip_address'
300+
```
301+
302+
To force JSON output in a TTY, use `--output json` (or `-o json`):
303+
304+
```bash
305+
createos projects get --project <id> --output json
306+
createos environments list --project <id> -o json
227307
```
228308

229309
## Options
230310

231-
| Flag | Description |
232-
| ------------- | ----------------------------------------------------- |
233-
| `--output json` | Output results as JSON (supported on most list/get commands) |
234-
| `--debug, -d` | Print HTTP request/response details (token is masked) |
235-
| `--api-url` | Override the API base URL |
311+
| Flag | Description |
312+
| --------------------- | -------------------------------------------------------------------- |
313+
| `--output, -o <fmt>` | Output format: `json` or `table` (default). Auto-json when piped. |
314+
| `--debug, -d` | Print HTTP request/response details (token is masked) |
315+
| `--api-url` | Override the API base URL |
236316

237317
## Security
238318

cmd/cronjobs/activities.go

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package cronjobs
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/pterm/pterm"
7+
"github.com/urfave/cli/v2"
8+
9+
"github.com/NodeOps-app/createos-cli/internal/api"
10+
"github.com/NodeOps-app/createos-cli/internal/output"
11+
)
12+
13+
func newCronjobsActivitiesCommand() *cli.Command {
14+
return &cli.Command{
15+
Name: "activities",
16+
Usage: "Show recent execution history for a cron job",
17+
Flags: []cli.Flag{
18+
&cli.StringFlag{Name: "project", Usage: "Project ID"},
19+
&cli.StringFlag{Name: "cronjob", Usage: "Cron job ID"},
20+
},
21+
Action: func(c *cli.Context) error {
22+
client, ok := c.App.Metadata[api.ClientKey].(*api.APIClient)
23+
if !ok {
24+
return fmt.Errorf("you're not signed in — run 'createos login' to get started")
25+
}
26+
27+
projectID, cronjobID, err := resolveCronjob(c, client)
28+
if err != nil {
29+
return err
30+
}
31+
32+
activities, err := client.ListCronjobActivities(projectID, cronjobID)
33+
if err != nil {
34+
return err
35+
}
36+
37+
output.Render(c, activities, func() {
38+
if len(activities) == 0 {
39+
fmt.Println("No execution history found for this cron job yet.")
40+
return
41+
}
42+
43+
tableData := pterm.TableData{
44+
{"ID", "Success", "Status Code", "Scheduled At", "Log"},
45+
}
46+
for _, a := range activities {
47+
success := "-"
48+
if a.Success != nil {
49+
if *a.Success {
50+
success = "yes"
51+
} else {
52+
success = "no"
53+
}
54+
}
55+
statusCode := "-"
56+
if a.StatusCode != nil {
57+
statusCode = fmt.Sprintf("%d", *a.StatusCode)
58+
}
59+
log := "-"
60+
if a.Log != nil && *a.Log != "" {
61+
log = *a.Log
62+
if len(log) > 80 {
63+
log = log[:77] + "..."
64+
}
65+
}
66+
tableData = append(tableData, []string{
67+
a.ID,
68+
success,
69+
statusCode,
70+
a.ScheduledAt.Format("2006-01-02 15:04:05"),
71+
log,
72+
})
73+
}
74+
_ = pterm.DefaultTable.WithHasHeader().WithData(tableData).Render()
75+
fmt.Println()
76+
})
77+
return nil
78+
},
79+
}
80+
}

0 commit comments

Comments
 (0)