Skip to content

Commit bb40662

Browse files
feat: regenerate CLI from OpenAPI spec
1 parent c8b1b3d commit bb40662

16 files changed

Lines changed: 2662 additions & 224 deletions

‎client/client.gen.go‎

Lines changed: 2152 additions & 224 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package nodejs
2+
3+
import (
4+
"context"
5+
"log"
6+
7+
"github.com/google/uuid"
8+
"github.com/hostinger/api-cli/api"
9+
"github.com/hostinger/api-cli/output"
10+
"github.com/spf13/cobra"
11+
)
12+
13+
var AnalyseFailedBuildCmd = &cobra.Command{
14+
Use: "analyse-failed-build <username> <domain> <uuid>",
15+
Short: "Analyse failed Node.js build",
16+
Long: "Returns an AI analysis of why a build failed and how to fix it, based on the build logs,\nthe project file list and package.json. Only builds in the `failed` state can be analysed;\nany other state returns 422. When no analysis could be produced both `analysis` and\n`solution` are null, in which case read `Get NodeJS build logs` instead.\n\nEach call runs the analysis again, so call it once per failed build and keep the result.\nLimited to 5 calls per minute per API client (429 above that).",
17+
Args: cobra.MatchAll(cobra.ExactArgs(3)),
18+
Run: func(cmd *cobra.Command, args []string) {
19+
r, err := api.Request().HostingAnalyseFailedNodeJsBuildV1WithResponse(context.TODO(), args[0], args[1], uuid.MustParse(args[2]))
20+
if err != nil {
21+
log.Fatal(err)
22+
}
23+
24+
output.Format(cmd, r.Body, r.StatusCode())
25+
},
26+
}

‎cmd/hosting/nodejs/build.go‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package nodejs
2+
3+
import (
4+
"context"
5+
"log"
6+
7+
"github.com/google/uuid"
8+
"github.com/hostinger/api-cli/api"
9+
"github.com/hostinger/api-cli/output"
10+
"github.com/spf13/cobra"
11+
)
12+
13+
var BuildCmd = &cobra.Command{
14+
Use: "build <username> <domain> <uuid>",
15+
Short: "Get Node.js build details",
16+
Long: "Returns one build by UUID: its state (`pending`, `running`, `completed`, `failed`), the\noptions it ran with and timestamps. Poll this while a build is pending or running. When it\nis failed, read `Get NodeJS build logs` and `Analyse failed Node.js build` for the cause.\nReturns 404 when the UUID does not belong to a build of this website.",
17+
Args: cobra.MatchAll(cobra.ExactArgs(3)),
18+
Run: func(cmd *cobra.Command, args []string) {
19+
r, err := api.Request().HostingGetNodeJsBuildDetailsV1WithResponse(context.TODO(), args[0], args[1], uuid.MustParse(args[2]))
20+
if err != nil {
21+
log.Fatal(err)
22+
}
23+
24+
output.Format(cmd, r.Body, r.StatusCode())
25+
},
26+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package nodejs
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 BuildSettingsCmd = &cobra.Command{
13+
Use: "build-settings <username> <domain>",
14+
Short: "Get Node.js build settings",
15+
Long: "Returns the build settings stored for the website: framework (`app_type`), Node.js version,\nroot and output directory, build script, entry file and package manager. Stored settings\ndrive Git auto-deployment builds. A build started through the API uses the values sent in\nthat request and saves them here only when no settings exist yet.\n\nReturns 404 until the first build or the first settings update stores them. Use this after\na failed build to check whether the framework or the entry file were detected wrong, then\nfix them with the `Update Node.js build settings` endpoint.",
16+
Args: cobra.MatchAll(cobra.ExactArgs(2)),
17+
Run: func(cmd *cobra.Command, args []string) {
18+
r, err := api.Request().HostingGetNodeJsBuildSettingsV1WithResponse(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+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package nodejs
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 ClearRuntimeLogsCmd = &cobra.Command{
13+
Use: "clear-runtime-logs <username> <domain>",
14+
Short: "Clear Node.js runtime logs",
15+
Long: "Empties the Node.js application's runtime log file. This cannot be undone, so confirm with\nthe user before calling it. Returns success even when no log file exists yet.\n\nUse it before reproducing a problem so the next `Get Node.js runtime logs` call returns\nonly fresh entries; start that call with `period` again instead of reusing a `from_line`\nfrom before the clear.",
16+
Args: cobra.MatchAll(cobra.ExactArgs(2)),
17+
Run: func(cmd *cobra.Command, args []string) {
18+
r, err := api.Request().HostingClearNodeJsRuntimeLogsV1WithResponse(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/nodejs/nodejs.go‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,19 @@ var GroupCmd = &cobra.Command{
1010
}
1111

1212
func init() {
13+
GroupCmd.AddCommand(AnalyseFailedBuildCmd)
14+
GroupCmd.AddCommand(BuildCmd)
1315
GroupCmd.AddCommand(BuildLogsCmd)
16+
GroupCmd.AddCommand(BuildSettingsCmd)
1417
GroupCmd.AddCommand(BuildSettingsFromArchiveCmd)
18+
GroupCmd.AddCommand(ClearRuntimeLogsCmd)
1519
GroupCmd.AddCommand(ListBuildsCmd)
1620
GroupCmd.AddCommand(ListEnvironmentVariablesCmd)
1721
GroupCmd.AddCommand(ListVulnerabilitiesCmd)
1822
GroupCmd.AddCommand(PatchVulnerabilitiesCmd)
1923
GroupCmd.AddCommand(ReplaceEnvironmentVariablesCmd)
2024
GroupCmd.AddCommand(RestartApplicationCmd)
25+
GroupCmd.AddCommand(RuntimeLogsCmd)
2126
GroupCmd.AddCommand(StartBuildCmd)
27+
GroupCmd.AddCommand(UpdateBuildSettingsCmd)
2228
}

‎cmd/hosting/nodejs/runtime_logs.go‎

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package nodejs
2+
3+
import (
4+
"context"
5+
"log"
6+
7+
"github.com/hostinger/api-cli/api"
8+
"github.com/hostinger/api-cli/client"
9+
"github.com/hostinger/api-cli/output"
10+
"github.com/hostinger/api-cli/utils"
11+
"github.com/spf13/cobra"
12+
)
13+
14+
var RuntimeLogsCmd = &cobra.Command{
15+
Use: "runtime-logs <username> <domain>",
16+
Short: "Get Node.js runtime logs",
17+
Long: "Returns the Node.js application's runtime console log entries, oldest first, each with\ntimestamp, level and message. On the first call send `period` (`1h`, `1d`, `1w` or `1m`)\nand optionally `levels` and `limit` (1-5000, default 1000); when more entries match than\n`limit`, the newest are kept.\n\nTo poll for new entries send `total_lines + 1` from the previous response as `from_line`\nand omit `period`; `period` and `from_line` cannot be combined. Lines that are not JSON\nwith a timestamp, level and message are skipped, so `logs` may hold fewer than `limit`\nentries while `total_lines` counts every raw line. Entries with a timestamp before\n`last_deployed_at` belong to the previous deployment. Returns an empty `logs` list when\nthe application has not written a log file yet.",
18+
Args: cobra.MatchAll(cobra.ExactArgs(2)),
19+
Run: func(cmd *cobra.Command, args []string) {
20+
utils.EnumCheck(cmd, "period", []string{"1h", "1d", "1w", "1m"})
21+
r, err := api.Request().HostingGetNodeJsRuntimeLogsV1WithResponse(context.TODO(), args[0], args[1], runtimeLogsParams(cmd))
22+
if err != nil {
23+
log.Fatal(err)
24+
}
25+
26+
output.Format(cmd, r.Body, r.StatusCode())
27+
},
28+
}
29+
30+
func init() {
31+
RuntimeLogsCmd.Flags().StringP("period", "", "", "Time window for the first fetch. Required when `from_line` is not sent. (one of: 1h, 1d, 1w, 1m)")
32+
RuntimeLogsCmd.Flags().IntP("from-line", "", 0, "1-based line of the log file to start from. For polling send `total_lines + 1` from the\nprevious response. Cannot be combined with `period`.")
33+
RuntimeLogsCmd.Flags().IntP("limit", "", 1000, "Maximum number of log entries to return. When more entries match, the newest are kept.")
34+
RuntimeLogsCmd.Flags().StringSliceP("levels", "", nil, "Return only entries with these log levels, sent as a comma-separated list, e.g. ERROR,WARN.\nMatching runs on the raw log line, so entries written with numeric levels (for example by\npino) are excluded while this filter is set. (one of: LOG, ERROR, WARN, INFO, DEBUG, TRACE)")
35+
}
36+
37+
func runtimeLogsParams(cmd *cobra.Command) *client.HostingGetNodeJsRuntimeLogsV1Params {
38+
params := &client.HostingGetNodeJsRuntimeLogsV1Params{}
39+
if cmd.Flags().Changed("period") {
40+
v, _ := cmd.Flags().GetString("period")
41+
e := client.HostingGetNodeJsRuntimeLogsV1ParamsPeriod(v)
42+
params.Period = &e
43+
}
44+
if cmd.Flags().Changed("from-line") {
45+
v, _ := cmd.Flags().GetInt("from-line")
46+
params.FromLine = &v
47+
}
48+
if cmd.Flags().Changed("limit") {
49+
v, _ := cmd.Flags().GetInt("limit")
50+
params.Limit = &v
51+
}
52+
if cmd.Flags().Changed("levels") {
53+
v, _ := cmd.Flags().GetStringSlice("levels")
54+
es := make([]client.HostingGetNodeJsRuntimeLogsV1ParamsLevels, len(v))
55+
for i, s := range v {
56+
es[i] = client.HostingGetNodeJsRuntimeLogsV1ParamsLevels(s)
57+
}
58+
params.Levels = &es
59+
}
60+
return params
61+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package nodejs
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/hostinger/api-cli/utils"
12+
"github.com/spf13/cobra"
13+
)
14+
15+
var UpdateBuildSettingsCmd = &cobra.Command{
16+
Use: "update-build-settings <username> <domain>",
17+
Short: "Update Node.js build settings",
18+
Long: "Replaces the build settings stored for the website. Send the full set: `node_version` is\nrequired and every nullable field you omit is stored as null. Creates the settings when\nnone exist yet.\n\nThis does not start a build. Stored settings drive Git auto-deployment builds; a build\nstarted through the API uses the values sent in that request, so to rebuild with corrected\nsettings call `Start Node.js build` with the same values. Typical fixes: a wrong `app_type`\nafter auto-detection, or a missing `entry_file` for express, fastify, nest, nuxt and hono\napps.",
19+
Args: cobra.MatchAll(cobra.ExactArgs(2)),
20+
Run: func(cmd *cobra.Command, args []string) {
21+
utils.EnumCheck(cmd, "app-type", []string{"create-react-app", "gatsby", "vite", "angular", "react", "vue", "parcel", "next", "nuxt", "nest", "express", "fastify", "astro", "svelte", "svelte-kit", "hono", "react-router", "nitro", "other"})
22+
utils.EnumCheck(cmd, "package-manager", []string{"npm", "yarn", "pnpm"})
23+
payload, err := json.Marshal(updateBuildSettingsBody(cmd))
24+
if err != nil {
25+
log.Fatal(err)
26+
}
27+
r, err := api.Request().HostingUpdateNodeJsBuildSettingsV1WithBodyWithResponse(context.TODO(), args[0], args[1], "application/json", bytes.NewReader(payload))
28+
if err != nil {
29+
log.Fatal(err)
30+
}
31+
32+
output.Format(cmd, r.Body, r.StatusCode())
33+
},
34+
}
35+
36+
func init() {
37+
UpdateBuildSettingsCmd.Flags().StringP("app-type", "", "", "Node.js application framework. Set it explicitly when auto-detection picked the wrong one. (one of: create-react-app, gatsby, vite, angular, react, vue, parcel, next, nuxt, nest, express, fastify, astro, svelte, svelte-kit, hono, react-router, nitro, other)")
38+
UpdateBuildSettingsCmd.Flags().StringP("build-script", "", "", "The package.json script that builds the application")
39+
UpdateBuildSettingsCmd.Flags().StringP("entry-file", "", "", "The main entry point file for the application\n(required for express, fastify, nest, nuxt and hono app types)")
40+
UpdateBuildSettingsCmd.Flags().IntP("node-version", "", 0, "Node.js major version (one of: 18, 20, 22, 24)")
41+
UpdateBuildSettingsCmd.Flags().StringP("output-directory", "", "", "Build output directory relative to the root directory")
42+
UpdateBuildSettingsCmd.Flags().StringP("package-manager", "", "", "Package manager used to install dependencies (one of: npm, yarn, pnpm)")
43+
UpdateBuildSettingsCmd.Flags().StringP("root-directory", "", "", "Application root directory (where package.json is located) relative to public_html.\nOmit it, or send \".\", for public_html itself.")
44+
UpdateBuildSettingsCmd.MarkFlagRequired("node-version")
45+
}
46+
47+
func updateBuildSettingsBody(cmd *cobra.Command) map[string]any {
48+
body := map[string]any{}
49+
if cmd.Flags().Changed("app-type") {
50+
v, _ := cmd.Flags().GetString("app-type")
51+
body["app_type"] = v
52+
}
53+
if cmd.Flags().Changed("build-script") {
54+
v, _ := cmd.Flags().GetString("build-script")
55+
body["build_script"] = v
56+
}
57+
if cmd.Flags().Changed("entry-file") {
58+
v, _ := cmd.Flags().GetString("entry-file")
59+
body["entry_file"] = v
60+
}
61+
nodeVersionVal, _ := cmd.Flags().GetInt("node-version")
62+
body["node_version"] = nodeVersionVal
63+
if cmd.Flags().Changed("output-directory") {
64+
v, _ := cmd.Flags().GetString("output-directory")
65+
body["output_directory"] = v
66+
}
67+
if cmd.Flags().Changed("package-manager") {
68+
v, _ := cmd.Flags().GetString("package-manager")
69+
body["package_manager"] = v
70+
}
71+
if cmd.Flags().Changed("root-directory") {
72+
v, _ := cmd.Flags().GetString("root-directory")
73+
body["root_directory"] = v
74+
}
75+
return body
76+
}

‎docs/hostinger_hosting_nodejs.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,19 @@ NodeJS commands
1818
### SEE ALSO
1919

2020
* [hostinger hosting](hostinger_hosting.md) - Hosting commands
21+
* [hostinger hosting nodejs analyse-failed-build](hostinger_hosting_nodejs_analyse-failed-build.md) - Analyse failed Node.js build
22+
* [hostinger hosting nodejs build](hostinger_hosting_nodejs_build.md) - Get Node.js build details
2123
* [hostinger hosting nodejs build-logs](hostinger_hosting_nodejs_build-logs.md) - Get NodeJS build logs
24+
* [hostinger hosting nodejs build-settings](hostinger_hosting_nodejs_build-settings.md) - Get Node.js build settings
2225
* [hostinger hosting nodejs build-settings-from-archive](hostinger_hosting_nodejs_build-settings-from-archive.md) - Get Node.js build settings from archive
26+
* [hostinger hosting nodejs clear-runtime-logs](hostinger_hosting_nodejs_clear-runtime-logs.md) - Clear Node.js runtime logs
2327
* [hostinger hosting nodejs list-builds](hostinger_hosting_nodejs_list-builds.md) - List NodeJS builds
2428
* [hostinger hosting nodejs list-environment-variables](hostinger_hosting_nodejs_list-environment-variables.md) - List Node.js environment variables
2529
* [hostinger hosting nodejs list-vulnerabilities](hostinger_hosting_nodejs_list-vulnerabilities.md) - List Node.js vulnerabilities
2630
* [hostinger hosting nodejs patch-vulnerabilities](hostinger_hosting_nodejs_patch-vulnerabilities.md) - Patch Node.js vulnerabilities
2731
* [hostinger hosting nodejs replace-environment-variables](hostinger_hosting_nodejs_replace-environment-variables.md) - Replace Node.js environment variables
2832
* [hostinger hosting nodejs restart-application](hostinger_hosting_nodejs_restart-application.md) - Restart Node.js application
33+
* [hostinger hosting nodejs runtime-logs](hostinger_hosting_nodejs_runtime-logs.md) - Get Node.js runtime logs
2934
* [hostinger hosting nodejs start-build](hostinger_hosting_nodejs_start-build.md) - Start Node.js build
35+
* [hostinger hosting nodejs update-build-settings](hostinger_hosting_nodejs_update-build-settings.md) - Update Node.js build settings
3036

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
## hostinger hosting nodejs analyse-failed-build
2+
3+
Analyse failed Node.js build
4+
5+
### Synopsis
6+
7+
Returns an AI analysis of why a build failed and how to fix it, based on the build logs,
8+
the project file list and package.json. Only builds in the `failed` state can be analysed;
9+
any other state returns 422. When no analysis could be produced both `analysis` and
10+
`solution` are null, in which case read `Get NodeJS build logs` instead.
11+
12+
Each call runs the analysis again, so call it once per failed build and keep the result.
13+
Limited to 5 calls per minute per API client (429 above that).
14+
15+
```
16+
hostinger hosting nodejs analyse-failed-build <username> <domain> <uuid> [flags]
17+
```
18+
19+
### Options
20+
21+
```
22+
-h, --help help for analyse-failed-build
23+
```
24+
25+
### Options inherited from parent commands
26+
27+
```
28+
--config string Config file (default is $HOME/.hostinger.yaml)
29+
--format string Output format type (json|table|tree), default: table
30+
```
31+
32+
### SEE ALSO
33+
34+
* [hostinger hosting nodejs](hostinger_hosting_nodejs.md) - NodeJS commands
35+

0 commit comments

Comments
 (0)