Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions .stats.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
configured_endpoints: 24
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openregister/openregister-4bd4cc957806a1fc7250db66762de302ee6718d21ebe7159b8753af53acc68df.yml
openapi_spec_hash: 2ada6c644f88094e8e542e539643f724
config_hash: 42520b3d15dbe4a67577eb9c86e4ed01
configured_endpoints: 26
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/goccy/go-yaml v1.18.0
github.com/itchyny/json2yaml v0.1.4
github.com/muesli/reflow v0.3.0
github.com/oregister/openregister-go/v2 v2.10.0
github.com/oregister/openregister-go/v2 v2.12.0
github.com/stretchr/testify v1.10.0
github.com/tidwall/gjson v1.18.0
github.com/tidwall/pretty v1.2.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ github.com/muesli/reflow v0.3.0 h1:IFsN6K9NfGtjeggFP+68I4chLZV2yIKsXJFNZ+eWh6s=
github.com/muesli/reflow v0.3.0/go.mod h1:pbwTDkVPibjO2kyvBQRBxTWEEGDGq0FlB1BIKtnHY/8=
github.com/muesli/termenv v0.16.0 h1:S5AlUN9dENB57rsbnkPyfdGuWIlkmzJjbFf0Tf5FWUc=
github.com/muesli/termenv v0.16.0/go.mod h1:ZRfOIKPFDYQoDFF4Olj7/QJbW60Ol/kL1pU3VfY/Cnk=
github.com/oregister/openregister-go/v2 v2.10.0 h1:SKV/Kco04Bd88vNo5jhO4WR2sw7swKsjokNV8ZspUZQ=
github.com/oregister/openregister-go/v2 v2.10.0/go.mod h1:CCIHIlKhI2GTYzCGjooEWb+Qmclab0n258lUEVuPKkA=
github.com/oregister/openregister-go/v2 v2.12.0 h1:UU3N0x2hPEMJjtLYwZlN2YpnGUu2O1acotxH8+ayBPo=
github.com/oregister/openregister-go/v2 v2.12.0/go.mod h1:CCIHIlKhI2GTYzCGjooEWb+Qmclab0n258lUEVuPKkA=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
Expand Down
10 changes: 9 additions & 1 deletion pkg/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ func init() {
},
&requestflag.Flag[string]{
Name: "api-key",
Usage: "API Key Authentication\nProvide your API key as a Bearer token in the Authorization header.\n",
Sources: cli.EnvVars("OPENREGISTER_API_KEY"),
},
},
Expand Down Expand Up @@ -172,6 +171,15 @@ func init() {
&insolvencyGetDetailsV1,
},
},
{
Name: "job",
Category: "API RESOURCE",
Suggest: true,
Commands: []*cli.Command{
&jobCreateV1,
&jobGetV1,
},
},
{
Name: "@manpages",
Usage: "Generate documentation for 'man'",
Expand Down
140 changes: 140 additions & 0 deletions pkg/cmd/job.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

package cmd

import (
"context"
"fmt"

"github.com/oregister/openregister-cli/internal/apiquery"
"github.com/oregister/openregister-cli/internal/requestflag"
"github.com/oregister/openregister-go/v2"
"github.com/oregister/openregister-go/v2/option"
"github.com/tidwall/gjson"
"github.com/urfave/cli/v3"
)

var jobCreateV1 = cli.Command{
Name: "create-v1",
Usage: "Start a realtime request without waiting for it. The request returns at once\nwith a pending job. Use this instead of `realtime=true` when your client cannot\nkeep a request open for the minutes the Handelsregister may take.",
Suggest: true,
Flags: []cli.Flag{
&requestflag.Flag[string]{
Name: "company-id",
Usage: "Unique company identifier.\nExample: DE-HRB-F1103-267645\n",
Required: true,
BodyPath: "company_id",
},
&requestflag.Flag[string]{
Name: "type",
Usage: `Allowed values: "company", "owners", "document".`,
Required: true,
BodyPath: "type",
},
&requestflag.Flag[string]{
Name: "document-category",
Usage: `Allowed values: "current_printout", "chronological_printout", "historical_printout", "structured_information", "shareholder_list", "articles_of_association".`,
BodyPath: "document_category",
},
},
Action: handleJobCreateV1,
HideHelpCommand: true,
}

var jobGetV1 = cli.Command{
Name: "get-v1",
Usage: "Get a job's status and, once it completed, its result in `results`. Polling is\nfree.",
Suggest: true,
Flags: []cli.Flag{
&requestflag.Flag[string]{
Name: "job-id",
Required: true,
PathParam: "job_id",
},
},
Action: handleJobGetV1,
HideHelpCommand: true,
}

func handleJobCreateV1(ctx context.Context, cmd *cli.Command) error {
client := openregister.NewClient(getDefaultRequestOptions(cmd)...)
unusedArgs := cmd.Args().Slice()

if len(unusedArgs) > 0 {
return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs)
}

options, err := flagOptions(
cmd,
apiquery.NestedQueryFormatBrackets,
apiquery.ArrayQueryFormatComma,
ApplicationJSON,
false,
)
if err != nil {
return err
}

params := openregister.JobNewV1Params{}

var res []byte
options = append(options, option.WithResponseBodyInto(&res))
_, err = client.Job.NewV1(ctx, params, options...)
if err != nil {
return err
}

obj := gjson.ParseBytes(res)
format := cmd.Root().String("format")
explicitFormat := cmd.Root().IsSet("format")
transform := cmd.Root().String("transform")
return ShowJSON(obj, ShowJSONOpts{
ExplicitFormat: explicitFormat,
Format: format,
RawOutput: cmd.Root().Bool("raw-output"),
Title: "job create-v1",
Transform: transform,
})
}

func handleJobGetV1(ctx context.Context, cmd *cli.Command) error {
client := openregister.NewClient(getDefaultRequestOptions(cmd)...)
unusedArgs := cmd.Args().Slice()
if !cmd.IsSet("job-id") && len(unusedArgs) > 0 {
cmd.Set("job-id", unusedArgs[0])
unusedArgs = unusedArgs[1:]
}
if len(unusedArgs) > 0 {
return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs)
}

options, err := flagOptions(
cmd,
apiquery.NestedQueryFormatBrackets,
apiquery.ArrayQueryFormatComma,
EmptyBody,
false,
)
if err != nil {
return err
}

var res []byte
options = append(options, option.WithResponseBodyInto(&res))
_, err = client.Job.GetV1(ctx, cmd.Value("job-id").(string), options...)
if err != nil {
return err
}

obj := gjson.ParseBytes(res)
format := cmd.Root().String("format")
explicitFormat := cmd.Root().IsSet("format")
transform := cmd.Root().String("transform")
return ShowJSON(obj, ShowJSONOpts{
ExplicitFormat: explicitFormat,
Format: format,
RawOutput: cmd.Root().Bool("raw-output"),
Title: "job get-v1",
Transform: transform,
})
}
48 changes: 48 additions & 0 deletions pkg/cmd/job_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

package cmd

import (
"testing"

"github.com/oregister/openregister-cli/internal/mocktest"
)

func TestJobCreateV1(t *testing.T) {
t.Skip("Mock server tests are disabled")
t.Run("regular flags", func(t *testing.T) {
mocktest.TestRunMockTestWithFlags(
t,
"--api-key", "string",
"job", "create-v1",
"--company-id", "company_id",
"--type", "company",
"--document-category", "current_printout",
)
})

t.Run("piping data", func(t *testing.T) {
// Test piping YAML data over stdin
pipeData := []byte("" +
"company_id: company_id\n" +
"type: company\n" +
"document_category: current_printout\n")
mocktest.TestRunMockTestWithPipeAndFlags(
t, pipeData,
"--api-key", "string",
"job", "create-v1",
)
})
}

func TestJobGetV1(t *testing.T) {
t.Skip("Mock server tests are disabled")
t.Run("regular flags", func(t *testing.T) {
mocktest.TestRunMockTestWithFlags(
t,
"--api-key", "string",
"job", "get-v1",
"--job-id", "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
)
})
}
2 changes: 1 addition & 1 deletion scripts/build
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set -euo pipefail
cd "$(dirname "$0")/.."

# Mark the necessary Go modules as private to avoid Go's proxy
export GOPRIVATE="${GOPRIVATE:+$GOPRIVATE,}github.com/oregister/openregister-go/v2,github.com/stainless-sdks/openregister-go/v2"
export GOPRIVATE="${GOPRIVATE:+$GOPRIVATE,}github.com/oregister/openregister-go"

echo "==> Building openregister"
go build ./cmd/openregister
2 changes: 1 addition & 1 deletion scripts/link
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set -euo pipefail
cd "$(dirname "$0")/.."

# Mark the necessary Go modules as private to avoid Go's proxy
export GOPRIVATE="${GOPRIVATE:+$GOPRIVATE,}github.com/oregister/openregister-go/v2,github.com/stainless-sdks/openregister-go/v2"
export GOPRIVATE="${GOPRIVATE:+$GOPRIVATE,}github.com/oregister/openregister-go"

REPLACEMENT="${1:-"../openregister-go"}"
echo "==> Replacing Go SDK with $REPLACEMENT"
Expand Down
2 changes: 1 addition & 1 deletion scripts/lint
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set -euo pipefail
cd "$(dirname "$0")/.."

# Mark the necessary Go modules as private to avoid Go's proxy
export GOPRIVATE="${GOPRIVATE:+$GOPRIVATE,}github.com/oregister/openregister-go/v2,github.com/stainless-sdks/openregister-go/v2"
export GOPRIVATE="${GOPRIVATE:+$GOPRIVATE,}github.com/oregister/openregister-go"

echo "==> Running Go build"
go build ./...
2 changes: 1 addition & 1 deletion scripts/run
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ set -euo pipefail
cd "$(dirname "$0")/.."

# Mark the necessary Go modules as private to avoid Go's proxy
export GOPRIVATE="${GOPRIVATE:+$GOPRIVATE,}github.com/oregister/openregister-go/v2,github.com/stainless-sdks/openregister-go/v2"
export GOPRIVATE="${GOPRIVATE:+$GOPRIVATE,}github.com/oregister/openregister-go"

go run ./cmd/openregister "$@"
2 changes: 1 addition & 1 deletion scripts/test
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set -euo pipefail
cd "$(dirname "$0")/.."

# Mark the necessary Go modules as private to avoid Go's proxy
export GOPRIVATE="${GOPRIVATE:+$GOPRIVATE,}github.com/oregister/openregister-go/v2,github.com/stainless-sdks/openregister-go/v2"
export GOPRIVATE="${GOPRIVATE:+$GOPRIVATE,}github.com/oregister/openregister-go"



Expand Down
Loading