diff --git a/.github/actions/setup-go/action.yml b/.github/actions/setup-go/action.yml new file mode 100644 index 0000000..8622879 --- /dev/null +++ b/.github/actions/setup-go/action.yml @@ -0,0 +1,29 @@ +name: Setup Go +description: 'Sets up Go environment with private modules' +inputs: + stainless-api-key: + required: false + description: the value of the STAINLESS_API_KEY secret +runs: + using: composite + steps: + - uses: stainless-api/retrieve-github-access-token@v1 + if: github.repository == 'stainless-sdks/y2-cli' + id: get_token + with: + repo: stainless-sdks/y2-go + stainless-api-key: ${{ inputs.stainless-api-key }} + + - name: Configure Git for access to the Go SDK's staging repo + if: github.repository == 'stainless-sdks/y2-cli' + shell: bash + run: git config --global url."https://x-access-token:${{ steps.get_token.outputs.github_access_token }}@github.com/stainless-sdks/y2-go".insteadOf "https://github.com/stainless-sdks/y2-go" + + - name: Setup go + uses: actions/setup-go@v5 + with: + go-version-file: ./go.mod + + - name: Bootstrap + shell: bash + run: ./scripts/bootstrap diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e3eca0f..7820b4c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,17 +1,22 @@ name: CI on: push: - branches-ignore: - - 'generated' - - 'codegen/**' - - 'integrated/**' - - 'stl-preview-head/**' - - 'stl-preview-base/**' + branches: + - '**' + - '!integrated/**' + - '!stl-preview-head/**' + - '!stl-preview-base/**' + - '!generated' + - '!codegen/**' + - 'codegen/stl/**' pull_request: branches-ignore: - 'stl-preview-head/**' - 'stl-preview-base/**' +env: + GOPRIVATE: github.com/y2-intel/y2-go,github.com/stainless-sdks/y2-go + jobs: lint: timeout-minutes: 10 @@ -22,10 +27,14 @@ jobs: steps: - uses: actions/checkout@v6 - - name: Setup go - uses: actions/setup-go@v5 + - uses: ./.github/actions/setup-go with: - go-version-file: ./go.mod + stainless-api-key: ${{ secrets.STAINLESS_API_KEY }} + + - name: Link staging branch + if: github.repository == 'stainless-sdks/y2-cli' + run: | + ./scripts/link 'github.com/stainless-sdks/y2-go@${{ github.ref_name }}' || true - name: Bootstrap run: ./scripts/bootstrap @@ -44,10 +53,14 @@ jobs: steps: - uses: actions/checkout@v6 - - name: Setup go - uses: actions/setup-go@v5 + - uses: ./.github/actions/setup-go with: - go-version-file: ./go.mod + stainless-api-key: ${{ secrets.STAINLESS_API_KEY }} + + - name: Link staging branch + if: github.repository == 'stainless-sdks/y2-cli' + run: | + ./scripts/link 'github.com/stainless-sdks/y2-go@${{ github.ref_name }}' || true - name: Bootstrap run: ./scripts/bootstrap @@ -61,14 +74,18 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Get GitHub OIDC Token - if: github.repository == 'stainless-sdks/y2-cli' + if: |- + github.repository == 'stainless-sdks/y2-cli' && + !startsWith(github.ref, 'refs/heads/stl/') id: github-oidc uses: actions/github-script@v8 with: script: core.setOutput('github_token', await core.getIDToken()); - name: Upload tarball - if: github.repository == 'stainless-sdks/y2-cli' + if: |- + github.repository == 'stainless-sdks/y2-cli' && + !startsWith(github.ref, 'refs/heads/stl/') env: URL: https://pkg.stainless.com/s AUTH: ${{ steps.github-oidc.outputs.github_token }} @@ -83,10 +100,14 @@ jobs: steps: - uses: actions/checkout@v6 - - name: Setup go - uses: actions/setup-go@v5 + - uses: ./.github/actions/setup-go with: - go-version-file: ./go.mod + stainless-api-key: ${{ secrets.STAINLESS_API_KEY }} + + - name: Link staging branch + if: github.repository == 'stainless-sdks/y2-cli' + run: | + ./scripts/link 'github.com/stainless-sdks/y2-go@${{ github.ref_name }}' || true - name: Bootstrap run: ./scripts/bootstrap diff --git a/.gitignore b/.gitignore index 2677b09..ca0e258 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .prism.log +.stdy.log dist/ /y2 *.exe diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 4208b5c..1b77f50 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "0.6.0" + ".": "0.7.0" } \ No newline at end of file diff --git a/.stats.yml b/.stats.yml index bdb16ee..6cb64d1 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 30 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/jedi-labs%2Fy2-2f9dde595a9741f91d2066b6912882a5814e1ea78b54bd2dabaa185f09b153e8.yml -openapi_spec_hash: 5af9f2fd5689a97d833b5cfb13b9558d +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/jedi-labs%2Fy2-4f7cb206ea938ef34326b6d48ceec8bf5edbb78826c0c3403551aa2693d56c2b.yml +openapi_spec_hash: fc1b2b74950aab022d89af6e70b0a4e2 config_hash: b16cfc4ab05ceee84810166970a3d683 diff --git a/CHANGELOG.md b/CHANGELOG.md index 08e26c5..9ce9368 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,32 @@ # Changelog +## 0.7.0 (2026-03-24) + +Full Changelog: [v0.6.0...v0.7.0](https://github.com/y2-intel/y2-cli/compare/v0.6.0...v0.7.0) + +### Features + +* add default description for enum CLI flags without an explicit description ([cae6e8e](https://github.com/y2-intel/y2-cli/commit/cae6e8e0cf7f370f7ad50bc7ac35fb4ba70f90b9)) + + +### Bug Fixes + +* avoid reading from stdin unless request body is form encoded or json ([0e4c7ff](https://github.com/y2-intel/y2-cli/commit/0e4c7ff960fc9c6ed75c35771e208c65ac693616)) +* better support passing client args in any position ([f39af5c](https://github.com/y2-intel/y2-cli/commit/f39af5c23769579b608d7acc1bd3d13a1b01a563)) +* cli no longer hangs when stdin is attached to a pipe with empty input ([6a14372](https://github.com/y2-intel/y2-cli/commit/6a143721fbb81b7cce43d0fb603c4bf2a89f829f)) +* fix for test cases with newlines in YAML and better error reporting ([e48f86f](https://github.com/y2-intel/y2-cli/commit/e48f86f78b72e6f328503427ce3979c509fc0dab)) +* improve linking behavior when developing on a branch not in the Go SDK ([31eaf83](https://github.com/y2-intel/y2-cli/commit/31eaf83bb47abcf4def03988f2c58e24a29db275)) +* improved workflow for developing on branches ([5ed568c](https://github.com/y2-intel/y2-cli/commit/5ed568c761725544ac69f02003ad1a783052788e)) +* no longer require an API key when building on production repos ([7f85ba7](https://github.com/y2-intel/y2-cli/commit/7f85ba7fecc326e1b5d9588272e79b5aa70cbbf3)) +* only set client options when the corresponding CLI flag or env var is explicitly set ([159a1d5](https://github.com/y2-intel/y2-cli/commit/159a1d51c58eaa04fb91f550388f269b3ab19c95)) + + +### Chores + +* **ci:** skip uploading artifacts on stainless-internal branches ([2e72da4](https://github.com/y2-intel/y2-cli/commit/2e72da41491d4480f2ab09d8cdc9657907bb87d8)) +* **internal:** tweak CI branches ([c581a0e](https://github.com/y2-intel/y2-cli/commit/c581a0e47b0be4c2a30d2a4a6b98ecb6c06874b5)) +* **internal:** update gitignore ([372e829](https://github.com/y2-intel/y2-cli/commit/372e829a974682f751ec67976577e3897b6343ba)) + ## 0.6.0 (2026-03-07) Full Changelog: [v0.5.0...v0.6.0](https://github.com/y2-intel/y2-cli/compare/v0.5.0...v0.6.0) diff --git a/internal/requestflag/requestflag.go b/internal/requestflag/requestflag.go index 986afed..21a8a69 100644 --- a/internal/requestflag/requestflag.go +++ b/internal/requestflag/requestflag.go @@ -374,6 +374,14 @@ func (f *Flag[T]) Count() int { return f.count } +// Implementation for the cli.LocalFlag interface +var _ cli.LocalFlag = (*Flag[any])(nil) // Type assertion to ensure interface compliance + +func (f Flag[T]) IsLocal() bool { + // By default, all request flags are local, i.e. can be provided at any part of the CLI command. + return true +} + // cliValue is a generic implementation of cli.Value for common types type cliValue[ T []any | []map[string]any | []DateTimeValue | []DateValue | []TimeValue | []string | []float64 | diff --git a/pkg/cmd/cmdutil.go b/pkg/cmd/cmdutil.go index 1987dc3..1860822 100644 --- a/pkg/cmd/cmdutil.go +++ b/pkg/cmd/cmdutil.go @@ -36,7 +36,9 @@ func getDefaultRequestOptions(cmd *cli.Command) []option.RequestOption { option.WithHeader("X-Stainless-Package-Version", Version), option.WithHeader("X-Stainless-Runtime", "cli"), option.WithHeader("X-Stainless-CLI-Command", cmd.FullName()), - option.WithAPIKey(cmd.String("api-key")), + } + if cmd.IsSet("api-key") { + opts = append(opts, option.WithAPIKey(cmd.String("api-key"))) } // Override base URL if the --base-url flag is provided @@ -68,9 +70,35 @@ var debugMiddlewareOption = option.WithMiddleware( }, ) +// isInputPiped tries to check for input being piped into the CLI which tells us that we should try to read +// from stdin. This can be a bit tricky in some cases like when an stdin is connected to a pipe but nothing is +// being piped in (this may happen in some environments like Cursor's integration terminal or CI), which is +// why this function is a little more elaborate than it'd be otherwise. func isInputPiped() bool { - stat, _ := os.Stdin.Stat() - return (stat.Mode() & os.ModeCharDevice) == 0 + stat, err := os.Stdin.Stat() + if err != nil { + return false + } + + mode := stat.Mode() + + // Regular file (redirect like < file.txt) — only if non-empty. + // + // Notably, on Unix the case like `< /dev/null` is handled below because `/dev/null` is not a regular + // file. On Windows, NUL appears as a regular file with size 0, so it's also handled correctly. + if mode.IsRegular() && stat.Size() > 0 { + return true + } + + // For pipes/sockets (e.g. `echo foo | stainlesscli`), use an OS-specific check to determine whether + // data is actually available. Some environments like Cursor's integrated terminal connect stdin as a + // pipe even when nothing is being piped. + if mode&(os.ModeNamedPipe|os.ModeSocket) != 0 { + // Defined in either cmdutil_unix.go or cmdutil_windows.go. + return isPipedDataAvailableOSSpecific() + } + + return false } func isTerminal(w io.Writer) bool { diff --git a/pkg/cmd/cmdutil_unix.go b/pkg/cmd/cmdutil_unix.go index f4a0e5c..edefcd7 100644 --- a/pkg/cmd/cmdutil_unix.go +++ b/pkg/cmd/cmdutil_unix.go @@ -12,6 +12,17 @@ import ( "golang.org/x/sys/unix" ) +func isPipedDataAvailableOSSpecific() bool { + // Try to determine if there's non-empty data being piped into the command by polling for data for a short + // amount of time. This is necessary because some environments (e.g. Cursor's integrated terminal) connect + // stdin as a pipe even when nothing is being piped, which would cause the command to block indefinitely + // waiting for input that will never come. The 10 ms timeout is arbitrary -- designed to be long enough to + // allow data to be detected, but short enough that it shouldn't cause a noticeable delay in command runs. + fds := []unix.PollFd{{Fd: int32(os.Stdin.Fd()), Events: unix.POLLIN}} + n, _ := unix.Poll(fds, 10 /* ms */) + return n > 0 +} + func streamOutputOSSpecific(label string, generateOutput func(w *os.File) error) error { // Try to use socket pair for better buffer control pagerInput, pid, err := openSocketPairPager(label) diff --git a/pkg/cmd/cmdutil_windows.go b/pkg/cmd/cmdutil_windows.go index 608adb7..49b025e 100644 --- a/pkg/cmd/cmdutil_windows.go +++ b/pkg/cmd/cmdutil_windows.go @@ -2,7 +2,31 @@ package cmd -import "os" +import ( + "os" + "syscall" + "unsafe" +) + +var ( + kernel32 = syscall.NewLazyDLL("kernel32.dll") + procPeekNamedPipe = kernel32.NewProc("PeekNamedPipe") +) + +func isPipedDataAvailableOSSpecific() bool { + // On Windows, unix.Poll is not available. Use PeekNamedPipe to check if data is available + // on the pipe without consuming it. + var available uint32 + r, _, _ := procPeekNamedPipe.Call( + os.Stdin.Fd(), + 0, + 0, + 0, + uintptr(unsafe.Pointer(&available)), + 0, + ) + return r != 0 && available > 0 +} func streamOutputOSSpecific(label string, generateOutput func(w *os.File) error) error { // We have a trick with sockets that we use when possible on Unix-like systems. Those APIs aren't diff --git a/pkg/cmd/flagoptions.go b/pkg/cmd/flagoptions.go index 7cfb0ae..48dd1a7 100644 --- a/pkg/cmd/flagoptions.go +++ b/pkg/cmd/flagoptions.go @@ -219,7 +219,7 @@ func flagOptions( requestContents := requestflag.ExtractRequestContents(cmd) - if bodyType != ApplicationOctetStream && isInputPiped() && !ignoreStdin { + if (bodyType == MultipartFormEncoded || bodyType == ApplicationJSON) && !ignoreStdin && isInputPiped() { pipeData, err := io.ReadAll(os.Stdin) if err != nil { return nil, err @@ -227,19 +227,20 @@ func flagOptions( if len(pipeData) > 0 { var bodyData any - if err := yaml.Unmarshal(pipeData, &bodyData); err == nil { - if bodyMap, ok := bodyData.(map[string]any); ok { - if flagMap, ok := requestContents.Body.(map[string]any); ok { - maps.Copy(bodyMap, flagMap) - requestContents.Body = bodyMap - } else { - bodyData = requestContents.Body - } - } else if flagMap, ok := requestContents.Body.(map[string]any); ok && len(flagMap) > 0 { - return nil, fmt.Errorf("Cannot merge flags with a body that is not a map: %v", bodyData) + if err := yaml.Unmarshal(pipeData, &bodyData); err != nil { + return nil, fmt.Errorf("Failed to parse piped data as YAML/JSON:\n%w", err) + } + if bodyMap, ok := bodyData.(map[string]any); ok { + if flagMap, ok := requestContents.Body.(map[string]any); ok { + maps.Copy(bodyMap, flagMap) + requestContents.Body = bodyMap } else { - requestContents.Body = bodyData + bodyData = requestContents.Body } + } else if flagMap, ok := requestContents.Body.(map[string]any); ok && len(flagMap) > 0 { + return nil, fmt.Errorf("Cannot merge flags with a body that is not a map: %v", bodyData) + } else { + requestContents.Body = bodyData } } } diff --git a/pkg/cmd/news_test.go b/pkg/cmd/news_test.go index c0d13f2..9befd5c 100644 --- a/pkg/cmd/news_test.go +++ b/pkg/cmd/news_test.go @@ -12,8 +12,9 @@ func TestNewsList(t *testing.T) { t.Skip("Mock server tests are disabled") t.Run("regular flags", func(t *testing.T) { mocktest.TestRunMockTestWithFlags( - t, "news", "list", + t, "--api-key", "string", + "news", "list", "--limit", "1", "--topics", "crypto,ai_agents,bitcoin", ) @@ -24,8 +25,9 @@ func TestNewsGetRecaps(t *testing.T) { t.Skip("Mock server tests are disabled") t.Run("regular flags", func(t *testing.T) { mocktest.TestRunMockTestWithFlags( - t, "news", "get-recaps", + t, "--api-key", "string", + "news", "get-recaps", "--timeframe", "12h", "--topics", "topics", ) @@ -36,8 +38,9 @@ func TestNewsListFeeds(t *testing.T) { t.Skip("Mock server tests are disabled") t.Run("regular flags", func(t *testing.T) { mocktest.TestRunMockTestWithFlags( - t, "news", "list-feeds", + t, "--api-key", "string", + "news", "list-feeds", ) }) } diff --git a/pkg/cmd/osint_test.go b/pkg/cmd/osint_test.go index 1f37a6d..67c6f4e 100644 --- a/pkg/cmd/osint_test.go +++ b/pkg/cmd/osint_test.go @@ -12,8 +12,9 @@ func TestOsintGetConflictIndicators(t *testing.T) { t.Skip("Mock server tests are disabled") t.Run("regular flags", func(t *testing.T) { mocktest.TestRunMockTestWithFlags( - t, "osint", "get-conflict-indicators", + t, "--api-key", "string", + "osint", "get-conflict-indicators", "--category", "seismic", "--limit", "1", "--region", "mena", @@ -25,8 +26,9 @@ func TestOsintGetGpsJammingZones(t *testing.T) { t.Skip("Mock server tests are disabled") t.Run("regular flags", func(t *testing.T) { mocktest.TestRunMockTestWithFlags( - t, "osint", "get-gps-jamming-zones", + t, "--api-key", "string", + "osint", "get-gps-jamming-zones", "--limit", "1", "--severity", "low", ) @@ -37,8 +39,9 @@ func TestOsintGetMilitaryPosture(t *testing.T) { t.Skip("Mock server tests are disabled") t.Run("regular flags", func(t *testing.T) { mocktest.TestRunMockTestWithFlags( - t, "osint", "get-military-posture", + t, "--api-key", "string", + "osint", "get-military-posture", "--limit", "1", ) }) @@ -48,8 +51,9 @@ func TestOsintListAircraft(t *testing.T) { t.Skip("Mock server tests are disabled") t.Run("regular flags", func(t *testing.T) { mocktest.TestRunMockTestWithFlags( - t, "osint", "list-aircraft", + t, "--api-key", "string", + "osint", "list-aircraft", "--limit", "1", "--theater", "theater", ) @@ -60,8 +64,9 @@ func TestOsintListEvents(t *testing.T) { t.Skip("Mock server tests are disabled") t.Run("regular flags", func(t *testing.T) { mocktest.TestRunMockTestWithFlags( - t, "osint", "list-events", + t, "--api-key", "string", + "osint", "list-events", "--category", "seismic", "--limit", "1", "--severity", "low", @@ -73,8 +78,9 @@ func TestOsintListVessels(t *testing.T) { t.Skip("Mock server tests are disabled") t.Run("regular flags", func(t *testing.T) { mocktest.TestRunMockTestWithFlags( - t, "osint", "list-vessels", + t, "--api-key", "string", + "osint", "list-vessels", "--limit", "1", "--region", "region", ) @@ -85,8 +91,9 @@ func TestOsintMapEvents(t *testing.T) { t.Skip("Mock server tests are disabled") t.Run("regular flags", func(t *testing.T) { mocktest.TestRunMockTestWithFlags( - t, "osint", "map-events", + t, "--api-key", "string", + "osint", "map-events", "--limit", "1", "--region", "mena", ) diff --git a/pkg/cmd/osintcountry_test.go b/pkg/cmd/osintcountry_test.go index 5ad8390..0f967e3 100644 --- a/pkg/cmd/osintcountry_test.go +++ b/pkg/cmd/osintcountry_test.go @@ -12,8 +12,9 @@ func TestOsintCountriesGetCountryInstabilityIndex(t *testing.T) { t.Skip("Mock server tests are disabled") t.Run("regular flags", func(t *testing.T) { mocktest.TestRunMockTestWithFlags( - t, "osint:countries", "get-country-instability-index", + t, "--api-key", "string", + "osint:countries", "get-country-instability-index", "--country-code", "UA", ) }) @@ -23,8 +24,9 @@ func TestOsintCountriesGetCountryNews(t *testing.T) { t.Skip("Mock server tests are disabled") t.Run("regular flags", func(t *testing.T) { mocktest.TestRunMockTestWithFlags( - t, "osint:countries", "get-country-news", + t, "--api-key", "string", + "osint:countries", "get-country-news", "--country-code", "US", "--limit", "1", ) @@ -35,8 +37,9 @@ func TestOsintCountriesGetIntelligenceBrief(t *testing.T) { t.Skip("Mock server tests are disabled") t.Run("regular flags", func(t *testing.T) { mocktest.TestRunMockTestWithFlags( - t, "osint:countries", "get-intelligence-brief", + t, "--api-key", "string", + "osint:countries", "get-intelligence-brief", "--country-code", "US", ) }) @@ -46,8 +49,9 @@ func TestOsintCountriesGetPredictionMarkets(t *testing.T) { t.Skip("Mock server tests are disabled") t.Run("regular flags", func(t *testing.T) { mocktest.TestRunMockTestWithFlags( - t, "osint:countries", "get-prediction-markets", + t, "--api-key", "string", + "osint:countries", "get-prediction-markets", "--country-code", "US", "--limit", "1", ) @@ -58,8 +62,9 @@ func TestOsintCountriesGetStockMarketIndex(t *testing.T) { t.Skip("Mock server tests are disabled") t.Run("regular flags", func(t *testing.T) { mocktest.TestRunMockTestWithFlags( - t, "osint:countries", "get-stock-market-index", + t, "--api-key", "string", + "osint:countries", "get-stock-market-index", "--country-code", "US", ) }) diff --git a/pkg/cmd/osintsource_test.go b/pkg/cmd/osintsource_test.go index f7dd28a..30bf906 100644 --- a/pkg/cmd/osintsource_test.go +++ b/pkg/cmd/osintsource_test.go @@ -12,8 +12,9 @@ func TestOsintSourcesGetDataSourceHealth(t *testing.T) { t.Skip("Mock server tests are disabled") t.Run("regular flags", func(t *testing.T) { mocktest.TestRunMockTestWithFlags( - t, "osint:sources", "get-data-source-health", + t, "--api-key", "string", + "osint:sources", "get-data-source-health", ) }) } diff --git a/pkg/cmd/profile.go b/pkg/cmd/profile.go index bfb49e7..89efe6d 100644 --- a/pkg/cmd/profile.go +++ b/pkg/cmd/profile.go @@ -189,6 +189,7 @@ var profilesCreate = requestflag.WithInnerFlags(cli.Command{ }, &requestflag.InnerFlag[string]{ Name: "recursion-config.strategy", + Usage: `Allowed values: "breadth-first", "depth-first", "hybrid".`, InnerField: "strategy", }, }, @@ -207,6 +208,7 @@ var profilesCreate = requestflag.WithInnerFlags(cli.Command{ }, &requestflag.InnerFlag[string]{ Name: "search-config.search-depth", + Usage: `Allowed values: "basic", "advanced".`, InnerField: "searchDepth", }, &requestflag.InnerFlag[string]{ @@ -379,6 +381,7 @@ var profilesUpdate = requestflag.WithInnerFlags(cli.Command{ }, &requestflag.InnerFlag[string]{ Name: "recursion-config.strategy", + Usage: `Allowed values: "breadth-first", "depth-first", "hybrid".`, InnerField: "strategy", }, }, @@ -397,6 +400,7 @@ var profilesUpdate = requestflag.WithInnerFlags(cli.Command{ }, &requestflag.InnerFlag[string]{ Name: "search-config.search-depth", + Usage: `Allowed values: "basic", "advanced".`, InnerField: "searchDepth", }, &requestflag.InnerFlag[string]{ @@ -592,6 +596,7 @@ var profilesPartialUpdate = requestflag.WithInnerFlags(cli.Command{ }, &requestflag.InnerFlag[string]{ Name: "recursion-config.strategy", + Usage: `Allowed values: "breadth-first", "depth-first", "hybrid".`, InnerField: "strategy", }, }, @@ -610,6 +615,7 @@ var profilesPartialUpdate = requestflag.WithInnerFlags(cli.Command{ }, &requestflag.InnerFlag[string]{ Name: "search-config.search-depth", + Usage: `Allowed values: "basic", "advanced".`, InnerField: "searchDepth", }, &requestflag.InnerFlag[string]{ diff --git a/pkg/cmd/profile_test.go b/pkg/cmd/profile_test.go index 635c135..45cb4a6 100644 --- a/pkg/cmd/profile_test.go +++ b/pkg/cmd/profile_test.go @@ -13,8 +13,9 @@ func TestProfilesCreate(t *testing.T) { t.Skip("Mock server tests are disabled") t.Run("regular flags", func(t *testing.T) { mocktest.TestRunMockTestWithFlags( - t, "profiles", "create", + t, "--api-key", "string", + "profiles", "create", "--frequency", "daily", "--name", "Cybersecurity Weekly", "--schedule-time-of-day", "09:00", @@ -42,8 +43,9 @@ func TestProfilesCreate(t *testing.T) { // Alternative argument passing style using inner flags mocktest.TestRunMockTestWithFlags( - t, "profiles", "create", + t, "--api-key", "string", + "profiles", "create", "--frequency", "daily", "--name", "Cybersecurity Weekly", "--schedule-time-of-day", "09:00", @@ -128,8 +130,9 @@ func TestProfilesCreate(t *testing.T) { " - string\n" + "toolConfig: {}\n") mocktest.TestRunMockTestWithPipeAndFlags( - t, pipeData, "profiles", "create", + t, pipeData, "--api-key", "string", + "profiles", "create", ) }) } @@ -138,8 +141,9 @@ func TestProfilesUpdate(t *testing.T) { t.Skip("Mock server tests are disabled") t.Run("regular flags", func(t *testing.T) { mocktest.TestRunMockTestWithFlags( - t, "profiles", "update", + t, "--api-key", "string", + "profiles", "update", "--profile-id", "k57abc123def456", "--audio-config", "{enabled: true, speed: 0, voiceId: voiceId}", "--bluf-structure", "blufStructure", @@ -168,8 +172,9 @@ func TestProfilesUpdate(t *testing.T) { // Alternative argument passing style using inner flags mocktest.TestRunMockTestWithFlags( - t, "profiles", "update", + t, "--api-key", "string", + "profiles", "update", "--profile-id", "k57abc123def456", "--audio-config.enabled=true", "--audio-config.speed", "0", @@ -255,8 +260,9 @@ func TestProfilesUpdate(t *testing.T) { " - string\n" + "topic: topic\n") mocktest.TestRunMockTestWithPipeAndFlags( - t, pipeData, "profiles", "update", + t, pipeData, "--api-key", "string", + "profiles", "update", "--profile-id", "k57abc123def456", ) }) @@ -266,8 +272,9 @@ func TestProfilesList(t *testing.T) { t.Skip("Mock server tests are disabled") t.Run("regular flags", func(t *testing.T) { mocktest.TestRunMockTestWithFlags( - t, "profiles", "list", + t, "--api-key", "string", + "profiles", "list", ) }) } @@ -276,8 +283,9 @@ func TestProfilesDelete(t *testing.T) { t.Skip("Mock server tests are disabled") t.Run("regular flags", func(t *testing.T) { mocktest.TestRunMockTestWithFlags( - t, "profiles", "delete", + t, "--api-key", "string", + "profiles", "delete", "--profile-id", "k57abc123def456", ) }) @@ -287,8 +295,9 @@ func TestProfilesPartialUpdate(t *testing.T) { t.Skip("Mock server tests are disabled") t.Run("regular flags", func(t *testing.T) { mocktest.TestRunMockTestWithFlags( - t, "profiles", "partial-update", + t, "--api-key", "string", + "profiles", "partial-update", "--profile-id", "k57abc123def456", "--audio-config", "{enabled: true, speed: 0, voiceId: voiceId}", "--bluf-structure", "blufStructure", @@ -317,8 +326,9 @@ func TestProfilesPartialUpdate(t *testing.T) { // Alternative argument passing style using inner flags mocktest.TestRunMockTestWithFlags( - t, "profiles", "partial-update", + t, "--api-key", "string", + "profiles", "partial-update", "--profile-id", "k57abc123def456", "--audio-config.enabled=true", "--audio-config.speed", "0", @@ -404,8 +414,9 @@ func TestProfilesPartialUpdate(t *testing.T) { " - string\n" + "topic: topic\n") mocktest.TestRunMockTestWithPipeAndFlags( - t, pipeData, "profiles", "partial-update", + t, pipeData, "--api-key", "string", + "profiles", "partial-update", "--profile-id", "k57abc123def456", ) }) diff --git a/pkg/cmd/report_test.go b/pkg/cmd/report_test.go index afefe85..cef9f51 100644 --- a/pkg/cmd/report_test.go +++ b/pkg/cmd/report_test.go @@ -12,8 +12,9 @@ func TestReportsRetrieve(t *testing.T) { t.Skip("Mock server tests are disabled") t.Run("regular flags", func(t *testing.T) { mocktest.TestRunMockTestWithFlags( - t, "reports", "retrieve", + t, "--api-key", "string", + "reports", "retrieve", "--report-id", "k57abc123def456", ) }) @@ -23,8 +24,9 @@ func TestReportsList(t *testing.T) { t.Skip("Mock server tests are disabled") t.Run("regular flags", func(t *testing.T) { mocktest.TestRunMockTestWithFlags( - t, "reports", "list", + t, "--api-key", "string", + "reports", "list", "--limit", "1", "--profile-id", "k57abc123def456", ) @@ -35,8 +37,9 @@ func TestReportsRetrieveAudio(t *testing.T) { t.Skip("Mock server tests are disabled") t.Run("regular flags", func(t *testing.T) { mocktest.TestRunMockTestWithFlags( - t, "reports", "retrieve-audio", + t, "--api-key", "string", + "reports", "retrieve-audio", "--report-id", "reportId", "--redirect=true", ) diff --git a/pkg/cmd/subscription_test.go b/pkg/cmd/subscription_test.go index 30785c5..21bacba 100644 --- a/pkg/cmd/subscription_test.go +++ b/pkg/cmd/subscription_test.go @@ -12,8 +12,9 @@ func TestSubscriptionsUpdateDelivery(t *testing.T) { t.Skip("Mock server tests are disabled") t.Run("regular flags", func(t *testing.T) { mocktest.TestRunMockTestWithFlags( - t, "subscriptions", "update-delivery", + t, "--api-key", "string", + "subscriptions", "update-delivery", "--subscription-id", "subscriptionId", "--delivery-method", "email", "--webhook-config-id", "webhookConfigId", @@ -26,8 +27,9 @@ func TestSubscriptionsUpdateDelivery(t *testing.T) { "deliveryMethod: email\n" + "webhookConfigId: webhookConfigId\n") mocktest.TestRunMockTestWithPipeAndFlags( - t, pipeData, "subscriptions", "update-delivery", + t, pipeData, "--api-key", "string", + "subscriptions", "update-delivery", "--subscription-id", "subscriptionId", ) }) diff --git a/pkg/cmd/version.go b/pkg/cmd/version.go index c1f2884..f37c8ca 100644 --- a/pkg/cmd/version.go +++ b/pkg/cmd/version.go @@ -2,4 +2,4 @@ package cmd -const Version = "0.6.0" // x-release-please-version +const Version = "0.7.0" // x-release-please-version diff --git a/pkg/cmd/webhook_test.go b/pkg/cmd/webhook_test.go index f36d045..7e9d35c 100644 --- a/pkg/cmd/webhook_test.go +++ b/pkg/cmd/webhook_test.go @@ -12,8 +12,9 @@ func TestWebhooksCreate(t *testing.T) { t.Skip("Mock server tests are disabled") t.Run("regular flags", func(t *testing.T) { mocktest.TestRunMockTestWithFlags( - t, "webhooks", "create", + t, "--api-key", "string", + "webhooks", "create", "--name", "My Webhook", "--url", "https://example.com/webhook", "--headers", "{foo: string}", @@ -30,8 +31,9 @@ func TestWebhooksCreate(t *testing.T) { " foo: string\n" + "secret: secret\n") mocktest.TestRunMockTestWithPipeAndFlags( - t, pipeData, "webhooks", "create", + t, pipeData, "--api-key", "string", + "webhooks", "create", ) }) } @@ -40,8 +42,9 @@ func TestWebhooksUpdate(t *testing.T) { t.Skip("Mock server tests are disabled") t.Run("regular flags", func(t *testing.T) { mocktest.TestRunMockTestWithFlags( - t, "webhooks", "update", + t, "--api-key", "string", + "webhooks", "update", "--webhook-id", "webhookId", "--headers", "{foo: string}", "--is-active=true", @@ -61,8 +64,9 @@ func TestWebhooksUpdate(t *testing.T) { "secret: secret\n" + "url: https://example.com\n") mocktest.TestRunMockTestWithPipeAndFlags( - t, pipeData, "webhooks", "update", + t, pipeData, "--api-key", "string", + "webhooks", "update", "--webhook-id", "webhookId", ) }) @@ -72,8 +76,9 @@ func TestWebhooksList(t *testing.T) { t.Skip("Mock server tests are disabled") t.Run("regular flags", func(t *testing.T) { mocktest.TestRunMockTestWithFlags( - t, "webhooks", "list", + t, "--api-key", "string", + "webhooks", "list", ) }) } @@ -82,8 +87,9 @@ func TestWebhooksDelete(t *testing.T) { t.Skip("Mock server tests are disabled") t.Run("regular flags", func(t *testing.T) { mocktest.TestRunMockTestWithFlags( - t, "webhooks", "delete", + t, "--api-key", "string", + "webhooks", "delete", "--webhook-id", "webhookId", ) }) @@ -93,8 +99,9 @@ func TestWebhooksTest(t *testing.T) { t.Skip("Mock server tests are disabled") t.Run("regular flags", func(t *testing.T) { mocktest.TestRunMockTestWithFlags( - t, "webhooks", "test", + t, "--api-key", "string", + "webhooks", "test", "--webhook-id", "webhookId", ) }) diff --git a/scripts/bootstrap b/scripts/bootstrap index d94c7d1..9ebb7d3 100755 --- a/scripts/bootstrap +++ b/scripts/bootstrap @@ -18,6 +18,5 @@ if [ -f "Brewfile" ] && [ "$(uname -s)" = "Darwin" ] && [ "$SKIP_BREW" != "1" ] echo } fi - echo "==> Installing Go dependencies…" -go mod tidy +go mod tidy -e || true diff --git a/scripts/build b/scripts/build index e19ff20..0ff14e2 100755 --- a/scripts/build +++ b/scripts/build @@ -1,8 +1,11 @@ #!/usr/bin/env bash -set -e +set -euo pipefail cd "$(dirname "$0")/.." +# Mark the necessary Go modules as private to avoid Go's proxy +export GOPRIVATE="${GOPRIVATE:+$GOPRIVATE,}github.com/y2-intel/y2-go,github.com/stainless-sdks/y2-go" + echo "==> Building y2" go build ./cmd/y2 diff --git a/scripts/link b/scripts/link index 998c59d..66e4db7 100755 --- a/scripts/link +++ b/scripts/link @@ -1,16 +1,13 @@ #!/usr/bin/env bash -set -e +set -euo pipefail cd "$(dirname "$0")/.." -if [[ -n "$1" ]]; then - LOCAL_GO="$1" - shift -else - LOCAL_GO=../y2-go -fi +# Mark the necessary Go modules as private to avoid Go's proxy +export GOPRIVATE="${GOPRIVATE:+$GOPRIVATE,}github.com/y2-intel/y2-go,github.com/stainless-sdks/y2-go" -echo "==> Linking with local directory" +REPLACEMENT="${1:-"../y2-go"}" +echo "==> Replacing Go SDK with $REPLACEMENT" +go mod edit -replace github.com/y2-intel/y2-go="$REPLACEMENT" go mod tidy -e -go mod edit -replace github.com/y2-intel/y2-go="$LOCAL_GO" diff --git a/scripts/lint b/scripts/lint index fa7ba1f..daf5ca4 100755 --- a/scripts/lint +++ b/scripts/lint @@ -1,8 +1,11 @@ #!/usr/bin/env bash -set -e +set -euo pipefail cd "$(dirname "$0")/.." +# Mark the necessary Go modules as private to avoid Go's proxy +export GOPRIVATE="${GOPRIVATE:+$GOPRIVATE,}github.com/y2-intel/y2-go,github.com/stainless-sdks/y2-go" + echo "==> Running Go build" go build ./... diff --git a/scripts/run b/scripts/run index 1d36a17..30af9df 100755 --- a/scripts/run +++ b/scripts/run @@ -1,7 +1,10 @@ #!/usr/bin/env bash -set -e +set -euo pipefail cd "$(dirname "$0")/.." +# Mark the necessary Go modules as private to avoid Go's proxy +export GOPRIVATE="${GOPRIVATE:+$GOPRIVATE,}github.com/y2-intel/y2-go,github.com/stainless-sdks/y2-go" + go run ./cmd/y2 "$@" diff --git a/scripts/test b/scripts/test index df2bd61..89bd396 100755 --- a/scripts/test +++ b/scripts/test @@ -4,6 +4,9 @@ set -euo pipefail cd "$(dirname "$0")/.." +# Mark the necessary Go modules as private to avoid Go's proxy +export GOPRIVATE="${GOPRIVATE:+$GOPRIVATE,}github.com/y2-intel/y2-go,github.com/stainless-sdks/y2-go" + echo "==> Running tests"