Skip to content

Commit 1309979

Browse files
fix: init impl
1 parent babfea3 commit 1309979

18 files changed

Lines changed: 134 additions & 101 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
.claude
2+
.createos.json

cmd/deployments/deployments_build_logs.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,27 @@ import (
77
"github.com/urfave/cli/v2"
88

99
"github.com/NodeOps-app/createos-cli/internal/api"
10+
"github.com/NodeOps-app/createos-cli/internal/cmdutil"
1011
)
1112

1213
func newDeploymentBuildLogsCommand() *cli.Command {
1314
return &cli.Command{
1415
Name: "build-logs",
1516
Usage: "Get build logs for a deployment",
16-
ArgsUsage: "<project-id> <deployment-id>",
17+
ArgsUsage: "[project-id] <deployment-id>",
1718
Description: "Fetches the build logs for a deployment.\n\n" +
1819
" To find your deployment ID, run:\n" +
1920
" createos projects deployments list <project-id>",
2021
Action: func(c *cli.Context) error {
21-
if c.NArg() < 2 {
22-
return fmt.Errorf("please provide a project ID and deployment ID\n\n Example:\n createos projects deployments build-logs <project-id> <deployment-id>")
23-
}
24-
2522
client, ok := c.App.Metadata[api.ClientKey].(*api.APIClient)
2623
if !ok {
2724
return fmt.Errorf("you're not signed in — run 'createos login' to get started")
2825
}
2926

30-
projectID := c.Args().Get(0)
31-
deploymentID := c.Args().Get(1)
27+
projectID, deploymentID, err := cmdutil.ResolveProjectScopedArg(c.Args().Slice(), "a deployment ID")
28+
if err != nil {
29+
return err
30+
}
3231

3332
entries, err := client.GetDeploymentBuildLogs(projectID, deploymentID)
3433
if err != nil {

cmd/deployments/deployments_delete.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,27 @@ import (
77
"github.com/urfave/cli/v2"
88

99
"github.com/NodeOps-app/createos-cli/internal/api"
10+
"github.com/NodeOps-app/createos-cli/internal/cmdutil"
1011
)
1112

1213
func newDeploymentDeleteCommand() *cli.Command {
1314
return &cli.Command{
1415
Name: "cancel",
1516
Usage: "Cancel a running deployment",
16-
ArgsUsage: "<project-id> <deployment-id>",
17+
ArgsUsage: "[project-id] <deployment-id>",
1718
Description: "Stops a deployment that is currently building or deploying.\n\n" +
1819
" To find your deployment ID, run:\n" +
1920
" createos projects deployments list <project-id>",
2021
Action: func(c *cli.Context) error {
21-
if c.NArg() < 2 {
22-
return fmt.Errorf("please provide a project ID and deployment ID\n\n Example:\n createos projects deployments cancel <project-id> <deployment-id>")
23-
}
24-
2522
client, ok := c.App.Metadata[api.ClientKey].(*api.APIClient)
2623
if !ok {
2724
return fmt.Errorf("you're not signed in — run 'createos login' to get started")
2825
}
2926

30-
projectID := c.Args().Get(0)
31-
deploymentID := c.Args().Get(1)
27+
projectID, deploymentID, err := cmdutil.ResolveProjectScopedArg(c.Args().Slice(), "a deployment ID")
28+
if err != nil {
29+
return err
30+
}
3231

3332
confirm, err := pterm.DefaultInteractiveConfirm.
3433
WithDefaultText(fmt.Sprintf("Are you sure you want to cancel deployment %q?", deploymentID)).

cmd/deployments/deployments_list.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,24 @@ import (
77
"github.com/urfave/cli/v2"
88

99
"github.com/NodeOps-app/createos-cli/internal/api"
10+
"github.com/NodeOps-app/createos-cli/internal/cmdutil"
1011
)
1112

1213
func newDeploymentsListCommand() *cli.Command {
1314
return &cli.Command{
1415
Name: "list",
1516
Usage: "List deployments for a project",
16-
ArgsUsage: "<project-id>",
17+
ArgsUsage: "[project-id]",
1718
Action: func(c *cli.Context) error {
18-
if c.NArg() == 0 {
19-
return fmt.Errorf("please provide a project ID\n\n To see your projects and their IDs, run:\n createos projects list")
20-
}
21-
2219
client, ok := c.App.Metadata[api.ClientKey].(*api.APIClient)
2320
if !ok {
2421
return fmt.Errorf("you're not signed in — run 'createos login' to get started")
2522
}
2623

27-
projectID := c.Args().First()
24+
projectID, err := cmdutil.ResolveProjectID(c.Args().First())
25+
if err != nil {
26+
return err
27+
}
2828
deployments, err := client.ListDeployments(projectID)
2929
if err != nil {
3030
return err

cmd/deployments/deployments_logs.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@ import (
1212
"github.com/urfave/cli/v2"
1313

1414
"github.com/NodeOps-app/createos-cli/internal/api"
15+
"github.com/NodeOps-app/createos-cli/internal/cmdutil"
1516
)
1617

1718
func newDeploymentLogsCommand() *cli.Command {
1819
return &cli.Command{
1920
Name: "logs",
2021
Usage: "Get logs for a deployment",
21-
ArgsUsage: "<project-id> <deployment-id>",
22+
ArgsUsage: "[project-id] <deployment-id>",
2223
Description: "Fetches the latest logs for a running deployment.\n\n" +
2324
" To find your deployment ID, run:\n" +
2425
" createos deployments list <project-id>",
@@ -35,17 +36,15 @@ func newDeploymentLogsCommand() *cli.Command {
3536
},
3637
},
3738
Action: func(c *cli.Context) error {
38-
if c.NArg() < 2 {
39-
return fmt.Errorf("please provide a project ID and deployment ID\n\n Example:\n createos deployments logs <project-id> <deployment-id>")
40-
}
41-
4239
client, ok := c.App.Metadata[api.ClientKey].(*api.APIClient)
4340
if !ok {
4441
return fmt.Errorf("you're not signed in — run 'createos login' to get started")
4542
}
4643

47-
projectID := c.Args().Get(0)
48-
deploymentID := c.Args().Get(1)
44+
projectID, deploymentID, err := cmdutil.ResolveProjectScopedArg(c.Args().Slice(), "a deployment ID")
45+
if err != nil {
46+
return err
47+
}
4948

5049
logs, err := client.GetDeploymentLogs(projectID, deploymentID)
5150
if err != nil {

cmd/deployments/deployments_retrigger.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,27 @@ import (
77
"github.com/urfave/cli/v2"
88

99
"github.com/NodeOps-app/createos-cli/internal/api"
10+
"github.com/NodeOps-app/createos-cli/internal/cmdutil"
1011
)
1112

1213
func newDeploymentRetriggerCommand() *cli.Command {
1314
return &cli.Command{
1415
Name: "retrigger",
1516
Usage: "Redeploy an existing deployment",
16-
ArgsUsage: "<project-id> <deployment-id>",
17+
ArgsUsage: "[project-id] <deployment-id>",
1718
Description: "Creates a new deployment based on an existing one.\n\n" +
1819
" To find your deployment ID, run:\n" +
1920
" createos projects deployments list <project-id>",
2021
Action: func(c *cli.Context) error {
21-
if c.NArg() < 2 {
22-
return fmt.Errorf("please provide a project ID and deployment ID\n\n Example:\n createos projects deployments retrigger <project-id> <deployment-id>")
23-
}
24-
2522
client, ok := c.App.Metadata[api.ClientKey].(*api.APIClient)
2623
if !ok {
2724
return fmt.Errorf("you're not signed in — run 'createos login' to get started")
2825
}
2926

30-
projectID := c.Args().Get(0)
31-
deploymentID := c.Args().Get(1)
27+
projectID, deploymentID, err := cmdutil.ResolveProjectScopedArg(c.Args().Slice(), "a deployment ID")
28+
if err != nil {
29+
return err
30+
}
3231

3332
if err := client.RetriggerDeployment(projectID, deploymentID); err != nil {
3433
return err

cmd/deployments/deployments_wakeup.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,27 @@ import (
77
"github.com/urfave/cli/v2"
88

99
"github.com/NodeOps-app/createos-cli/internal/api"
10+
"github.com/NodeOps-app/createos-cli/internal/cmdutil"
1011
)
1112

1213
func newDeploymentWakeupCommand() *cli.Command {
1314
return &cli.Command{
1415
Name: "wakeup",
1516
Usage: "Wake up a sleeping deployment",
16-
ArgsUsage: "<project-id> <deployment-id>",
17+
ArgsUsage: "[project-id] <deployment-id>",
1718
Description: "Resumes a deployment that is currently sleeping.\n\n" +
1819
" To find your deployment ID, run:\n" +
1920
" createos projects deployments list <project-id>",
2021
Action: func(c *cli.Context) error {
21-
if c.NArg() < 2 {
22-
return fmt.Errorf("please provide a project ID and deployment ID\n\n Example:\n createos projects deployments wakeup <project-id> <deployment-id>")
23-
}
24-
2522
client, ok := c.App.Metadata[api.ClientKey].(*api.APIClient)
2623
if !ok {
2724
return fmt.Errorf("you're not signed in — run 'createos login' to get started")
2825
}
2926

30-
projectID := c.Args().Get(0)
31-
deploymentID := c.Args().Get(1)
27+
projectID, deploymentID, err := cmdutil.ResolveProjectScopedArg(c.Args().Slice(), "a deployment ID")
28+
if err != nil {
29+
return err
30+
}
3231

3332
if err := client.WakeupDeployment(projectID, deploymentID); err != nil {
3433
return err

cmd/domains/domains_add.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,27 @@ import (
77
"github.com/urfave/cli/v2"
88

99
"github.com/NodeOps-app/createos-cli/internal/api"
10+
"github.com/NodeOps-app/createos-cli/internal/cmdutil"
1011
)
1112

1213
func newDomainsAddCommand() *cli.Command {
1314
return &cli.Command{
1415
Name: "add",
1516
Usage: "Add a custom domain to a project",
16-
ArgsUsage: "<project-id> <domain>",
17+
ArgsUsage: "[project-id] <domain>",
1718
Description: "Adds a custom domain to your project.\n\n" +
1819
" After adding, point your DNS to the provided records, then run:\n" +
1920
" createos domains refresh <project-id> <domain-id>",
2021
Action: func(c *cli.Context) error {
21-
if c.NArg() < 2 {
22-
return fmt.Errorf("please provide a project ID and domain name\n\n Example:\n createos domains add <project-id> myapp.com")
23-
}
24-
2522
client, ok := c.App.Metadata[api.ClientKey].(*api.APIClient)
2623
if !ok {
2724
return fmt.Errorf("you're not signed in — run 'createos login' to get started")
2825
}
2926

30-
projectID := c.Args().Get(0)
31-
name := c.Args().Get(1)
27+
projectID, name, err := cmdutil.ResolveProjectScopedArg(c.Args().Slice(), "a domain name")
28+
if err != nil {
29+
return err
30+
}
3231

3332
id, err := client.AddDomain(projectID, name)
3433
if err != nil {

cmd/domains/domains_delete.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,27 @@ import (
77
"github.com/urfave/cli/v2"
88

99
"github.com/NodeOps-app/createos-cli/internal/api"
10+
"github.com/NodeOps-app/createos-cli/internal/cmdutil"
1011
)
1112

1213
func newDomainsDeleteCommand() *cli.Command {
1314
return &cli.Command{
1415
Name: "delete",
1516
Usage: "Remove a custom domain from a project",
16-
ArgsUsage: "<project-id> <domain-id>",
17+
ArgsUsage: "[project-id] <domain-id>",
1718
Description: "Permanently removes a custom domain from your project.\n\n" +
1819
" To find your domain ID, run:\n" +
1920
" createos domains list <project-id>",
2021
Action: func(c *cli.Context) error {
21-
if c.NArg() < 2 {
22-
return fmt.Errorf("please provide a project ID and domain ID\n\n Example:\n createos domains delete <project-id> <domain-id>")
23-
}
24-
2522
client, ok := c.App.Metadata[api.ClientKey].(*api.APIClient)
2623
if !ok {
2724
return fmt.Errorf("you're not signed in — run 'createos login' to get started")
2825
}
2926

30-
projectID := c.Args().Get(0)
31-
domainID := c.Args().Get(1)
27+
projectID, domainID, err := cmdutil.ResolveProjectScopedArg(c.Args().Slice(), "a domain ID")
28+
if err != nil {
29+
return err
30+
}
3231

3332
confirm, err := pterm.DefaultInteractiveConfirm.
3433
WithDefaultText(fmt.Sprintf("Are you sure you want to remove domain %q from this project?", domainID)).

cmd/domains/domains_list.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,24 @@ import (
77
"github.com/urfave/cli/v2"
88

99
"github.com/NodeOps-app/createos-cli/internal/api"
10+
"github.com/NodeOps-app/createos-cli/internal/cmdutil"
1011
)
1112

1213
func newDomainsListCommand() *cli.Command {
1314
return &cli.Command{
1415
Name: "list",
1516
Usage: "List all custom domains for a project",
16-
ArgsUsage: "<project-id>",
17+
ArgsUsage: "[project-id]",
1718
Action: func(c *cli.Context) error {
18-
if c.NArg() == 0 {
19-
return fmt.Errorf("please provide a project ID\n\n To see your projects and their IDs, run:\n createos projects list")
20-
}
21-
2219
client, ok := c.App.Metadata[api.ClientKey].(*api.APIClient)
2320
if !ok {
2421
return fmt.Errorf("you're not signed in — run 'createos login' to get started")
2522
}
2623

27-
projectID := c.Args().First()
24+
projectID, err := cmdutil.ResolveProjectID(c.Args().First())
25+
if err != nil {
26+
return err
27+
}
2828
domains, err := client.ListDomains(projectID)
2929
if err != nil {
3030
return err

0 commit comments

Comments
 (0)