Skip to content

Commit 68fcb1e

Browse files
chore: cli update
1 parent a732a71 commit 68fcb1e

14 files changed

Lines changed: 941 additions & 0 deletions

‎client/client.gen.go‎

Lines changed: 630 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎cmd/hosting/cron_jobs/create.go‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package cron_jobs
2+
3+
import (
4+
"bytes"
5+
"context"
6+
"encoding/json"
7+
"log"
8+
9+
"github.com/hostinger/api-cli/api"
10+
"github.com/hostinger/api-cli/output"
11+
"github.com/spf13/cobra"
12+
)
13+
14+
var CreateCmd = &cobra.Command{
15+
Use: "create <username>",
16+
Short: "Create account cron job",
17+
Long: "Creates a cron job for the specified account from a schedule expression and a command.\n\nReturns the created cron job, including its uid, which is required to delete the cron job or fetch its output.",
18+
Args: cobra.MatchAll(cobra.ExactArgs(1)),
19+
Run: func(cmd *cobra.Command, args []string) {
20+
payload, err := json.Marshal(createBody(cmd))
21+
if err != nil {
22+
log.Fatal(err)
23+
}
24+
r, err := api.Request().HostingCreateAccountCronJobV1WithBodyWithResponse(context.TODO(), args[0], "application/json", bytes.NewReader(payload))
25+
if err != nil {
26+
log.Fatal(err)
27+
}
28+
29+
output.Format(cmd, r.Body, r.StatusCode())
30+
},
31+
}
32+
33+
func init() {
34+
CreateCmd.Flags().StringP("command", "", "", "Command to execute on the schedule.")
35+
CreateCmd.Flags().StringP("time", "", "", "Cron schedule expression (for example \"0 2 * * *\" runs daily at 02:00).")
36+
CreateCmd.MarkFlagRequired("command")
37+
CreateCmd.MarkFlagRequired("time")
38+
}
39+
40+
func createBody(cmd *cobra.Command) map[string]any {
41+
body := map[string]any{}
42+
commandVal, _ := cmd.Flags().GetString("command")
43+
body["command"] = commandVal
44+
timeVal, _ := cmd.Flags().GetString("time")
45+
body["time"] = timeVal
46+
return body
47+
}

‎cmd/hosting/cron_jobs/cron_jobs.go‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package cron_jobs
2+
3+
import (
4+
"github.com/spf13/cobra"
5+
)
6+
7+
var GroupCmd = &cobra.Command{
8+
Use: "cron-jobs",
9+
Short: "Cron Jobs commands",
10+
}
11+
12+
func init() {
13+
GroupCmd.AddCommand(CreateCmd)
14+
GroupCmd.AddCommand(DeleteCmd)
15+
GroupCmd.AddCommand(ListCmd)
16+
GroupCmd.AddCommand(OutputCmd)
17+
}

‎cmd/hosting/cron_jobs/delete.go‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package cron_jobs
2+
3+
import (
4+
"context"
5+
"log"
6+
7+
"github.com/hostinger/api-cli/api"
8+
"github.com/hostinger/api-cli/output"
9+
"github.com/spf13/cobra"
10+
)
11+
12+
var DeleteCmd = &cobra.Command{
13+
Use: "delete <username> <uid>",
14+
Short: "Delete account cron job",
15+
Long: "Permanently deletes the cron job identified by its uid.\n\nThe uid is returned by the list cron jobs endpoint.",
16+
Args: cobra.MatchAll(cobra.ExactArgs(2)),
17+
Run: func(cmd *cobra.Command, args []string) {
18+
r, err := api.Request().HostingDeleteAccountCronJobV1WithResponse(context.TODO(), args[0], args[1])
19+
if err != nil {
20+
log.Fatal(err)
21+
}
22+
23+
output.Format(cmd, r.Body, r.StatusCode())
24+
},
25+
}

‎cmd/hosting/cron_jobs/list.go‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package cron_jobs
2+
3+
import (
4+
"context"
5+
"log"
6+
7+
"github.com/hostinger/api-cli/api"
8+
"github.com/hostinger/api-cli/output"
9+
"github.com/spf13/cobra"
10+
)
11+
12+
var ListCmd = &cobra.Command{
13+
Use: "list <username>",
14+
Short: "List account cron jobs",
15+
Long: "Returns the list of cron jobs configured for the specified account, including their schedule and command.",
16+
Args: cobra.MatchAll(cobra.ExactArgs(1)),
17+
Run: func(cmd *cobra.Command, args []string) {
18+
r, err := api.Request().HostingListAccountCronJobsV1WithResponse(context.TODO(), args[0])
19+
if err != nil {
20+
log.Fatal(err)
21+
}
22+
23+
output.Format(cmd, r.Body, r.StatusCode())
24+
},
25+
}

‎cmd/hosting/cron_jobs/output.go‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package cron_jobs
2+
3+
import (
4+
"context"
5+
"log"
6+
7+
"github.com/hostinger/api-cli/api"
8+
"github.com/hostinger/api-cli/output"
9+
"github.com/spf13/cobra"
10+
)
11+
12+
var OutputCmd = &cobra.Command{
13+
Use: "output <username> <uid>",
14+
Short: "Get cron job output",
15+
Long: "Returns the output captured from the last execution of the cron job identified by its uid.\n\nThe uid is returned by the list cron jobs endpoint.",
16+
Args: cobra.MatchAll(cobra.ExactArgs(2)),
17+
Run: func(cmd *cobra.Command, args []string) {
18+
r, err := api.Request().HostingGetCronJobOutputV1WithResponse(context.TODO(), args[0], args[1])
19+
if err != nil {
20+
log.Fatal(err)
21+
}
22+
23+
output.Format(cmd, r.Body, r.StatusCode())
24+
},
25+
}

‎cmd/hosting/hosting.go‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package hosting
22

33
import (
4+
"github.com/hostinger/api-cli/cmd/hosting/cron_jobs"
45
"github.com/hostinger/api-cli/cmd/hosting/databases"
56
"github.com/hostinger/api-cli/cmd/hosting/datacenters"
67
"github.com/hostinger/api-cli/cmd/hosting/domains"
@@ -18,6 +19,7 @@ var GroupCmd = &cobra.Command{
1819
}
1920

2021
func init() {
22+
GroupCmd.AddCommand(cron_jobs.GroupCmd)
2123
GroupCmd.AddCommand(databases.GroupCmd)
2224
GroupCmd.AddCommand(datacenters.GroupCmd)
2325
GroupCmd.AddCommand(domains.GroupCmd)

‎docs/hostinger_hosting.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Hosting commands
1818
### SEE ALSO
1919

2020
* [hostinger](hostinger.md) - Hostinger API Command Line Interface
21+
* [hostinger hosting cron-jobs](hostinger_hosting_cron-jobs.md) - Cron Jobs commands
2122
* [hostinger hosting databases](hostinger_hosting_databases.md) - Databases commands
2223
* [hostinger hosting datacenters](hostinger_hosting_datacenters.md) - Datacenters commands
2324
* [hostinger hosting domains](hostinger_hosting_domains.md) - Domains commands
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
## hostinger hosting cron-jobs
2+
3+
Cron Jobs commands
4+
5+
### Options
6+
7+
```
8+
-h, --help help for cron-jobs
9+
```
10+
11+
### Options inherited from parent commands
12+
13+
```
14+
--config string Config file (default is $HOME/.hostinger.yaml)
15+
--format string Output format type (json|table|tree), default: table
16+
```
17+
18+
### SEE ALSO
19+
20+
* [hostinger hosting](hostinger_hosting.md) - Hosting commands
21+
* [hostinger hosting cron-jobs create](hostinger_hosting_cron-jobs_create.md) - Create account cron job
22+
* [hostinger hosting cron-jobs delete](hostinger_hosting_cron-jobs_delete.md) - Delete account cron job
23+
* [hostinger hosting cron-jobs list](hostinger_hosting_cron-jobs_list.md) - List account cron jobs
24+
* [hostinger hosting cron-jobs output](hostinger_hosting_cron-jobs_output.md) - Get cron job output
25+
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
## hostinger hosting cron-jobs create
2+
3+
Create account cron job
4+
5+
### Synopsis
6+
7+
Creates a cron job for the specified account from a schedule expression and a command.
8+
9+
Returns the created cron job, including its uid, which is required to delete the cron job or fetch its output.
10+
11+
```
12+
hostinger hosting cron-jobs create <username> [flags]
13+
```
14+
15+
### Options
16+
17+
```
18+
--command string Command to execute on the schedule.
19+
-h, --help help for create
20+
--time string Cron schedule expression (for example "0 2 * * *" runs daily at 02:00).
21+
```
22+
23+
### Options inherited from parent commands
24+
25+
```
26+
--config string Config file (default is $HOME/.hostinger.yaml)
27+
--format string Output format type (json|table|tree), default: table
28+
```
29+
30+
### SEE ALSO
31+
32+
* [hostinger hosting cron-jobs](hostinger_hosting_cron-jobs.md) - Cron Jobs commands
33+

0 commit comments

Comments
 (0)