Skip to content

Commit 9cef29e

Browse files
authored
fix: add apps get command with server-side hint passthrough (#19)
1 parent 6a1e8e3 commit 9cef29e

3 files changed

Lines changed: 61 additions & 4 deletions

File tree

cmd/onecli/apps.go

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,16 @@ import (
99
"github.com/onecli/onecli-cli/pkg/validate"
1010
)
1111

12+
// configureResult is the structured response after configuring an app.
13+
type configureResult struct {
14+
App string `json:"app"`
15+
Status string `json:"status"`
16+
}
17+
1218
// AppsCmd is the `onecli apps` command group.
1319
type AppsCmd struct {
1420
List AppsListCmd `cmd:"" help:"List all apps with config and connection status."`
21+
Get AppsGetCmd `cmd:"" help:"Get a single app with setup guidance."`
1522
Configure AppsConfigureCmd `cmd:"" help:"Save OAuth credentials (BYOC) for a provider."`
1623
Remove AppsRemoveCmd `cmd:"" help:"Remove OAuth credentials for a provider."`
1724
Disconnect AppsDisconnectCmd `cmd:"" help:"Disconnect an app connection."`
@@ -42,6 +49,34 @@ func (c *AppsListCmd) Run(out *output.Writer) error {
4249
return out.WriteFiltered(apps, c.Fields)
4350
}
4451

52+
// AppsGetCmd is `onecli apps get`.
53+
type AppsGetCmd struct {
54+
Provider string `required:"" help:"Provider name (e.g. 'github', 'gmail')."`
55+
Fields string `optional:"" help:"Comma-separated list of fields to include in output."`
56+
}
57+
58+
func (c *AppsGetCmd) Run(out *output.Writer) error {
59+
if err := validate.ResourceID(c.Provider); err != nil {
60+
return fmt.Errorf("invalid provider: %w", err)
61+
}
62+
63+
client, err := newClient()
64+
if err != nil {
65+
return err
66+
}
67+
app, err := client.GetApp(newContext(), c.Provider)
68+
if err != nil {
69+
return err
70+
}
71+
72+
if app.Hint != "" {
73+
out.SetHint(app.Hint)
74+
app.Hint = ""
75+
}
76+
77+
return out.WriteFiltered(app, c.Fields)
78+
}
79+
4580
// AppsConfigureCmd is `onecli apps configure`.
4681
type AppsConfigureCmd struct {
4782
Provider string `required:"" help:"Provider name (e.g. 'github', 'gmail')."`
@@ -85,9 +120,18 @@ func (c *AppsConfigureCmd) Run(out *output.Writer) error {
85120
return err
86121
}
87122

88-
return out.Write(map[string]string{
89-
"status": "configured",
90-
"provider": c.Provider,
123+
app, err := client.GetApp(newContext(), c.Provider)
124+
if err != nil {
125+
return err
126+
}
127+
128+
if app.Hint != "" {
129+
out.SetHint(app.Hint)
130+
}
131+
132+
return out.Write(configureResult{
133+
App: c.Provider,
134+
Status: "configured",
91135
})
92136
}
93137

cmd/onecli/help.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ func (cmd *HelpCmd) Run(out *output.Writer) error {
8080
{Name: "--id", Required: true, Description: "ID of the secret to delete."},
8181
}},
8282
{Name: "apps list", Description: "List all apps with config and connection status."},
83+
{Name: "apps get", Description: "Get a single app with setup guidance.", Args: []ArgInfo{
84+
{Name: "--provider", Required: true, Description: "Provider name (e.g. 'github', 'gmail')."},
85+
}},
8386
{Name: "apps configure", Description: "Save OAuth credentials (BYOC) for a provider.", Args: []ArgInfo{
8487
{Name: "--provider", Required: true, Description: "Provider name (e.g. 'github', 'gmail')."},
8588
{Name: "--client-id", Required: true, Description: "OAuth client ID."},

internal/api/apps.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"net/http"
77
)
88

9-
// App represents an app from the unified /api/apps listing.
9+
// App represents an app from the /api/apps endpoints.
1010
type App struct {
1111
ID string `json:"id"`
1212
Name string `json:"name"`
@@ -15,6 +15,7 @@ type App struct {
1515
Configurable bool `json:"configurable"`
1616
Config *AppConfig `json:"config"`
1717
Connection *AppConnection `json:"connection"`
18+
Hint string `json:"hint,omitempty"`
1819
}
1920

2021
// AppConfig is the BYOC credential configuration status.
@@ -45,6 +46,15 @@ func (c *Client) ListApps(ctx context.Context) ([]App, error) {
4546
return apps, nil
4647
}
4748

49+
// GetApp returns a single app by provider name.
50+
func (c *Client) GetApp(ctx context.Context, provider string) (*App, error) {
51+
var app App
52+
if err := c.do(ctx, http.MethodGet, "/api/apps/"+provider, nil, &app); err != nil {
53+
return nil, fmt.Errorf("getting app: %w", err)
54+
}
55+
return &app, nil
56+
}
57+
4858
// ConfigureApp saves BYOC credentials for a provider.
4959
func (c *Client) ConfigureApp(ctx context.Context, provider string, input ConfigAppInput) error {
5060
var resp SuccessResponse

0 commit comments

Comments
 (0)