fivetran-cli 0.1.3__tar.gz → 0.1.7__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of fivetran-cli might be problematic. Click here for more details.

Files changed (20) hide show
  1. {fivetran_cli-0.1.3/src/fivetran_cli.egg-info → fivetran_cli-0.1.7}/PKG-INFO +35 -20
  2. {fivetran_cli-0.1.3 → fivetran_cli-0.1.7}/README.md +32 -18
  3. {fivetran_cli-0.1.3 → fivetran_cli-0.1.7}/pyproject.toml +5 -6
  4. {fivetran_cli-0.1.3 → fivetran_cli-0.1.7}/src/fivetran_cli/__init__.py +1 -1
  5. {fivetran_cli-0.1.3 → fivetran_cli-0.1.7}/src/fivetran_cli/cli.py +124 -2
  6. {fivetran_cli-0.1.3 → fivetran_cli-0.1.7/src/fivetran_cli.egg-info}/PKG-INFO +35 -20
  7. {fivetran_cli-0.1.3 → fivetran_cli-0.1.7}/src/fivetran_cli.egg-info/SOURCES.txt +1 -1
  8. fivetran_cli-0.1.7/src/fivetran_cli.egg-info/requires.txt +1 -0
  9. {fivetran_cli-0.1.3 → fivetran_cli-0.1.7}/tests/test_cli.py +116 -1
  10. fivetran_cli-0.1.3/src/fivetran_cli.egg-info/entry_points.txt +0 -2
  11. {fivetran_cli-0.1.3 → fivetran_cli-0.1.7}/LICENSE +0 -0
  12. {fivetran_cli-0.1.3 → fivetran_cli-0.1.7}/MANIFEST.in +0 -0
  13. {fivetran_cli-0.1.3 → fivetran_cli-0.1.7}/setup.cfg +0 -0
  14. {fivetran_cli-0.1.3 → fivetran_cli-0.1.7}/src/fivetran_cli/__main__.py +0 -0
  15. {fivetran_cli-0.1.3 → fivetran_cli-0.1.7}/src/fivetran_cli/client.py +0 -0
  16. {fivetran_cli-0.1.3 → fivetran_cli-0.1.7}/src/fivetran_cli/output.py +0 -0
  17. {fivetran_cli-0.1.3 → fivetran_cli-0.1.7}/src/fivetran_cli.egg-info/dependency_links.txt +0 -0
  18. {fivetran_cli-0.1.3 → fivetran_cli-0.1.7}/src/fivetran_cli.egg-info/top_level.txt +0 -0
  19. {fivetran_cli-0.1.3 → fivetran_cli-0.1.7}/tests/test_client.py +0 -0
  20. {fivetran_cli-0.1.3 → fivetran_cli-0.1.7}/tests/test_output.py +0 -0
@@ -1,7 +1,7 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fivetran-cli
3
- Version: 0.1.3
4
- Summary: Command line wrapper for the Fivetran REST API
3
+ Version: 0.1.7
4
+ Summary: Command line wrapper for the Fivetran REST API and Connector SDK
5
5
  Author: Fivetran
6
6
  License-Expression: MIT
7
7
  Classifier: Environment :: Console
@@ -12,21 +12,37 @@ Classifier: Programming Language :: Python :: 3.12
12
12
  Requires-Python: >=3.11
13
13
  Description-Content-Type: text/markdown
14
14
  License-File: LICENSE
15
+ Requires-Dist: fivetran-connector-sdk>=2.9.2
15
16
  Dynamic: license-file
16
17
 
17
18
  # fivetran-cli
18
19
 
19
- Thin command line wrapper around the Fivetran REST API.
20
+ Thin command line wrapper around the Fivetran REST API and Connector SDK.
20
21
 
21
22
  ```text
22
23
  fivetran [global-options] <resource> <operation> [arguments] [options]
23
24
  ```
24
25
 
25
- Credentials default to `FIVETRAN_API_KEY`. Set it to the single Base64-encoded API key shown by Fivetran.
26
+ ## Installation
27
+
28
+ ```bash
29
+ python3 -m pip install -U fivetran-cli
30
+ ```
31
+
32
+ Verify the installed CLI:
33
+
34
+ ```bash
35
+ fivetran --help
36
+ fivetran deploy --help
37
+ fivetran connection list --help
38
+ ```
39
+
40
+ Credentials default to `FIVETRAN_API_KEY`. Set it to the single Base64-encoded API key shown by Fivetran. Or you can also pass it in via `--api-key` option.
26
41
 
27
42
  ```bash
28
43
  fivetran --api-key "$FIVETRAN_API_KEY" connection list
29
44
  fivetran connection create --data-file connection.json
45
+ fivetran deploy
30
46
  ```
31
47
 
32
48
  ## Usage
@@ -103,12 +119,24 @@ Transformations:
103
119
 
104
120
  - `transformation list`
105
121
 
122
+ Connector SDK:
123
+
124
+ - `init`
125
+ - `debug`
126
+ - `deploy`
127
+ - `package`
128
+ - `reset`
129
+ - `version`
130
+ - `help`
131
+
132
+ Connector SDK commands are provided by `fivetran-connector-sdk` and remain at their existing top-level shape, for example `fivetran deploy`.
133
+
106
134
  ## Not Included Yet
107
135
 
108
136
  These API areas are still intentionally not implemented:
109
137
 
110
138
  - Certificates and fingerprints
111
- - Connector SDK packages
139
+ - REST API endpoints for Connector SDK package upload/download
112
140
  - Log services
113
141
  - Webhooks
114
142
  - Transformation create/get/update/delete/run/cancel/upgrade
@@ -148,25 +176,12 @@ Validate the generated artifacts:
148
176
  twine check dist/*
149
177
  ```
150
178
 
151
- Upload to TestPyPI first:
152
-
153
- ```bash
154
- twine upload --repository testpypi dist/*
155
- ```
156
-
157
- Install from TestPyPI in a clean environment:
158
-
159
- ```bash
160
- python3 -m pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ fivetran-cli
161
- fivetran --help
162
- ```
163
-
164
- Upload to PyPI after the TestPyPI package is verified:
179
+ Upload to PyPI:
165
180
 
166
181
  ```bash
167
182
  twine upload dist/*
168
183
  ```
169
184
 
170
- These upload commands assume `~/.pypirc` is configured with the `pypi` and `testpypi` repositories. If `~/.pypirc` is not configured, set `TWINE_USERNAME=__token__` and `TWINE_PASSWORD=<api-token>` before running `twine upload`.
185
+ This upload command assumes `~/.pypirc` is configured with the `pypi` repository. If `~/.pypirc` is not configured, set `TWINE_USERNAME=__token__` and `TWINE_PASSWORD=<api-token>` before running `twine upload`.
171
186
 
172
187
  PyPI files are immutable for a published version. If an upload is wrong, bump the version in `pyproject.toml`, rebuild, re-check, and upload the new version.
@@ -1,16 +1,31 @@
1
1
  # fivetran-cli
2
2
 
3
- Thin command line wrapper around the Fivetran REST API.
3
+ Thin command line wrapper around the Fivetran REST API and Connector SDK.
4
4
 
5
5
  ```text
6
6
  fivetran [global-options] <resource> <operation> [arguments] [options]
7
7
  ```
8
8
 
9
- Credentials default to `FIVETRAN_API_KEY`. Set it to the single Base64-encoded API key shown by Fivetran.
9
+ ## Installation
10
+
11
+ ```bash
12
+ python3 -m pip install -U fivetran-cli
13
+ ```
14
+
15
+ Verify the installed CLI:
16
+
17
+ ```bash
18
+ fivetran --help
19
+ fivetran deploy --help
20
+ fivetran connection list --help
21
+ ```
22
+
23
+ Credentials default to `FIVETRAN_API_KEY`. Set it to the single Base64-encoded API key shown by Fivetran. Or you can also pass it in via `--api-key` option.
10
24
 
11
25
  ```bash
12
26
  fivetran --api-key "$FIVETRAN_API_KEY" connection list
13
27
  fivetran connection create --data-file connection.json
28
+ fivetran deploy
14
29
  ```
15
30
 
16
31
  ## Usage
@@ -87,12 +102,24 @@ Transformations:
87
102
 
88
103
  - `transformation list`
89
104
 
105
+ Connector SDK:
106
+
107
+ - `init`
108
+ - `debug`
109
+ - `deploy`
110
+ - `package`
111
+ - `reset`
112
+ - `version`
113
+ - `help`
114
+
115
+ Connector SDK commands are provided by `fivetran-connector-sdk` and remain at their existing top-level shape, for example `fivetran deploy`.
116
+
90
117
  ## Not Included Yet
91
118
 
92
119
  These API areas are still intentionally not implemented:
93
120
 
94
121
  - Certificates and fingerprints
95
- - Connector SDK packages
122
+ - REST API endpoints for Connector SDK package upload/download
96
123
  - Log services
97
124
  - Webhooks
98
125
  - Transformation create/get/update/delete/run/cancel/upgrade
@@ -132,25 +159,12 @@ Validate the generated artifacts:
132
159
  twine check dist/*
133
160
  ```
134
161
 
135
- Upload to TestPyPI first:
136
-
137
- ```bash
138
- twine upload --repository testpypi dist/*
139
- ```
140
-
141
- Install from TestPyPI in a clean environment:
142
-
143
- ```bash
144
- python3 -m pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ fivetran-cli
145
- fivetran --help
146
- ```
147
-
148
- Upload to PyPI after the TestPyPI package is verified:
162
+ Upload to PyPI:
149
163
 
150
164
  ```bash
151
165
  twine upload dist/*
152
166
  ```
153
167
 
154
- These upload commands assume `~/.pypirc` is configured with the `pypi` and `testpypi` repositories. If `~/.pypirc` is not configured, set `TWINE_USERNAME=__token__` and `TWINE_PASSWORD=<api-token>` before running `twine upload`.
168
+ This upload command assumes `~/.pypirc` is configured with the `pypi` repository. If `~/.pypirc` is not configured, set `TWINE_USERNAME=__token__` and `TWINE_PASSWORD=<api-token>` before running `twine upload`.
155
169
 
156
170
  PyPI files are immutable for a published version. If an upload is wrong, bump the version in `pyproject.toml`, rebuild, re-check, and upload the new version.
@@ -4,8 +4,8 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "fivetran-cli"
7
- version = "0.1.3"
8
- description = "Command line wrapper for the Fivetran REST API"
7
+ version = "0.1.7"
8
+ description = "Command line wrapper for the Fivetran REST API and Connector SDK"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.11"
11
11
  authors = [
@@ -19,10 +19,9 @@ classifiers = [
19
19
  "Programming Language :: Python :: 3.11",
20
20
  "Programming Language :: Python :: 3.12",
21
21
  ]
22
- dependencies = []
23
-
24
- [project.scripts]
25
- fivetran = "fivetran_cli.cli:main"
22
+ dependencies = [
23
+ "fivetran-connector-sdk>=2.9.2",
24
+ ]
26
25
 
27
26
  [tool.setuptools.packages.find]
28
27
  where = ["src"]
@@ -1,3 +1,3 @@
1
1
  """Fivetran CLI package."""
2
2
 
3
- __version__ = "0.1.1"
3
+ __version__ = "0.1.6"
@@ -16,6 +16,24 @@ from .output import emit_output
16
16
 
17
17
 
18
18
  Handler = Callable[[argparse.Namespace, FivetranClient], Any]
19
+ REST_RESOURCE_NAMES = {
20
+ "account",
21
+ "connection",
22
+ "connection-schema",
23
+ "connector-metadata",
24
+ "destination",
25
+ "group",
26
+ "hybrid-deployment-agent",
27
+ "private-link",
28
+ "proxy-agent",
29
+ "public-connector",
30
+ "role",
31
+ "system-key",
32
+ "team",
33
+ "transformation",
34
+ "user",
35
+ }
36
+ SDK_TOP_LEVEL_OPTIONS = {"--version"}
19
37
  GLOBAL_OPTIONS_WITH_VALUES = {
20
38
  "--api-key",
21
39
  "--profile",
@@ -56,6 +74,10 @@ class SuggestingParser(argparse.ArgumentParser):
56
74
  super().error(message)
57
75
 
58
76
 
77
+ class HelpFormatter(argparse.ArgumentDefaultsHelpFormatter, argparse.RawDescriptionHelpFormatter):
78
+ pass
79
+
80
+
59
81
  def main(argv: Sequence[str] | None = None) -> int:
60
82
  return run(argv if argv is not None else sys.argv[1:])
61
83
 
@@ -64,10 +86,22 @@ def run(
64
86
  argv: Sequence[str],
65
87
  *,
66
88
  client_factory: Callable[[ClientConfig], FivetranClient] = FivetranClient,
89
+ sdk_runner: Callable[[Sequence[str]], int | None] | None = None,
67
90
  stdout: TextIO = sys.stdout,
68
91
  stderr: TextIO = sys.stderr,
69
92
  ) -> int:
93
+ if _should_delegate_to_sdk(argv):
94
+ try:
95
+ return _run_sdk(argv, sdk_runner=sdk_runner)
96
+ except CliError as exc:
97
+ stderr.write(f"fivetran: error: {exc}\n")
98
+ return 1
99
+
70
100
  parser = build_parser()
101
+ if _is_top_level_help_request(argv):
102
+ parser.print_help(stdout)
103
+ return 0
104
+
71
105
  args = parser.parse_args(_normalize_global_options(list(argv)))
72
106
  if not hasattr(args, "handler"):
73
107
  parser.print_help(stdout)
@@ -94,8 +128,8 @@ def run(
94
128
  def build_parser() -> argparse.ArgumentParser:
95
129
  parser = SuggestingParser(
96
130
  prog="fivetran",
97
- description="Command line wrapper for the Fivetran REST API.",
98
- formatter_class=argparse.ArgumentDefaultsHelpFormatter,
131
+ description="Command line wrapper for the Fivetran REST API and Connector SDK.",
132
+ formatter_class=HelpFormatter,
99
133
  allow_abbrev=False,
100
134
  )
101
135
  _add_global_options(parser)
@@ -116,9 +150,15 @@ def build_parser() -> argparse.ArgumentParser:
116
150
  _add_proxy_agent(resources)
117
151
  _add_private_link(resources)
118
152
  _add_transformation(resources)
153
+ _add_sdk_commands(resources)
119
154
  return parser
120
155
 
121
156
 
157
+ def _add_sdk_commands(resources: argparse._SubParsersAction[argparse.ArgumentParser]) -> None:
158
+ for command, help_text in _sdk_command_help():
159
+ resources.add_parser(command, help=help_text, description=help_text)
160
+
161
+
122
162
  def _add_global_options(parser: argparse.ArgumentParser) -> None:
123
163
  parser.add_argument(
124
164
  "--api-key",
@@ -133,6 +173,11 @@ def _add_global_options(parser: argparse.ArgumentParser) -> None:
133
173
  parser.add_argument("--output", help="Write output to a path instead of stdout.")
134
174
  parser.add_argument("--quiet", action="store_true", help="Suppress response output.")
135
175
  parser.add_argument("--verbose", action="store_true", help="Enable verbose diagnostics.")
176
+ parser.add_argument(
177
+ "--version",
178
+ action="store_true",
179
+ help="Print the fivetran_connector_sdk version and exit.",
180
+ )
136
181
 
137
182
 
138
183
  def _output_format(args: argparse.Namespace) -> str:
@@ -1328,6 +1373,83 @@ def _normalize_global_options(argv: list[str]) -> list[str]:
1328
1373
  return [*global_args, *command_args]
1329
1374
 
1330
1375
 
1376
+ def _should_delegate_to_sdk(argv: Sequence[str]) -> bool:
1377
+ if any(token in SDK_TOP_LEVEL_OPTIONS for token in argv):
1378
+ return True
1379
+ command = _first_command_token(argv)
1380
+ if command is None:
1381
+ return False
1382
+ if command in REST_RESOURCE_NAMES:
1383
+ return False
1384
+ if get_close_matches(command, REST_RESOURCE_NAMES, n=1):
1385
+ return False
1386
+ return True
1387
+
1388
+
1389
+ def _is_top_level_help_request(argv: Sequence[str]) -> bool:
1390
+ return _first_command_token(argv) is None and any(token in {"-h", "--help"} for token in argv)
1391
+
1392
+
1393
+ def _first_command_token(argv: Sequence[str]) -> str | None:
1394
+ index = 0
1395
+ while index < len(argv):
1396
+ token = argv[index]
1397
+ option_name = token.split("=", 1)[0]
1398
+ if option_name in GLOBAL_OPTIONS_WITH_VALUES:
1399
+ if "=" not in token:
1400
+ index += 1
1401
+ elif token in GLOBAL_FLAG_OPTIONS:
1402
+ pass
1403
+ elif token.startswith("-"):
1404
+ pass
1405
+ else:
1406
+ return token
1407
+ index += 1
1408
+ return None
1409
+
1410
+
1411
+ def _run_sdk(
1412
+ argv: Sequence[str],
1413
+ *,
1414
+ sdk_runner: Callable[[Sequence[str]], int | None] | None = None,
1415
+ ) -> int:
1416
+ if sdk_runner is not None:
1417
+ return _normalize_exit_code(sdk_runner(argv))
1418
+ try:
1419
+ from fivetran_connector_sdk.cli import main as sdk_main
1420
+ except ModuleNotFoundError as exc:
1421
+ if exc.name not in {"fivetran_connector_sdk", "fivetran_connector_sdk.cli"}:
1422
+ raise
1423
+ raise CliError(
1424
+ "Connector SDK commands require fivetran-connector-sdk to be installed."
1425
+ ) from exc
1426
+ return _normalize_exit_code(sdk_main(list(argv)))
1427
+
1428
+
1429
+ def _normalize_exit_code(code: int | None) -> int:
1430
+ return 0 if code is None else int(code)
1431
+
1432
+
1433
+ def _sdk_command_help() -> tuple[tuple[str, str], ...]:
1434
+ try:
1435
+ from fivetran_connector_sdk.cli_parser import create_argument_parser
1436
+ except ModuleNotFoundError as exc:
1437
+ if exc.name and exc.name.split(".", 1)[0] == "fivetran_connector_sdk":
1438
+ return ()
1439
+ raise
1440
+
1441
+ sdk_parser = create_argument_parser()
1442
+ commands: list[tuple[str, str]] = []
1443
+ for action in sdk_parser._actions:
1444
+ if not isinstance(action, argparse._SubParsersAction):
1445
+ continue
1446
+ for choice in action._choices_actions:
1447
+ if choice.help is argparse.SUPPRESS:
1448
+ continue
1449
+ commands.append((choice.dest, choice.help or ""))
1450
+ return tuple(commands)
1451
+
1452
+
1331
1453
  def _add_body_options(parser: argparse.ArgumentParser, *, required: bool) -> None:
1332
1454
  group = parser.add_mutually_exclusive_group(required=required)
1333
1455
  group.add_argument("--data", help="Raw JSON request body.")
@@ -1,7 +1,7 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fivetran-cli
3
- Version: 0.1.3
4
- Summary: Command line wrapper for the Fivetran REST API
3
+ Version: 0.1.7
4
+ Summary: Command line wrapper for the Fivetran REST API and Connector SDK
5
5
  Author: Fivetran
6
6
  License-Expression: MIT
7
7
  Classifier: Environment :: Console
@@ -12,21 +12,37 @@ Classifier: Programming Language :: Python :: 3.12
12
12
  Requires-Python: >=3.11
13
13
  Description-Content-Type: text/markdown
14
14
  License-File: LICENSE
15
+ Requires-Dist: fivetran-connector-sdk>=2.9.2
15
16
  Dynamic: license-file
16
17
 
17
18
  # fivetran-cli
18
19
 
19
- Thin command line wrapper around the Fivetran REST API.
20
+ Thin command line wrapper around the Fivetran REST API and Connector SDK.
20
21
 
21
22
  ```text
22
23
  fivetran [global-options] <resource> <operation> [arguments] [options]
23
24
  ```
24
25
 
25
- Credentials default to `FIVETRAN_API_KEY`. Set it to the single Base64-encoded API key shown by Fivetran.
26
+ ## Installation
27
+
28
+ ```bash
29
+ python3 -m pip install -U fivetran-cli
30
+ ```
31
+
32
+ Verify the installed CLI:
33
+
34
+ ```bash
35
+ fivetran --help
36
+ fivetran deploy --help
37
+ fivetran connection list --help
38
+ ```
39
+
40
+ Credentials default to `FIVETRAN_API_KEY`. Set it to the single Base64-encoded API key shown by Fivetran. Or you can also pass it in via `--api-key` option.
26
41
 
27
42
  ```bash
28
43
  fivetran --api-key "$FIVETRAN_API_KEY" connection list
29
44
  fivetran connection create --data-file connection.json
45
+ fivetran deploy
30
46
  ```
31
47
 
32
48
  ## Usage
@@ -103,12 +119,24 @@ Transformations:
103
119
 
104
120
  - `transformation list`
105
121
 
122
+ Connector SDK:
123
+
124
+ - `init`
125
+ - `debug`
126
+ - `deploy`
127
+ - `package`
128
+ - `reset`
129
+ - `version`
130
+ - `help`
131
+
132
+ Connector SDK commands are provided by `fivetran-connector-sdk` and remain at their existing top-level shape, for example `fivetran deploy`.
133
+
106
134
  ## Not Included Yet
107
135
 
108
136
  These API areas are still intentionally not implemented:
109
137
 
110
138
  - Certificates and fingerprints
111
- - Connector SDK packages
139
+ - REST API endpoints for Connector SDK package upload/download
112
140
  - Log services
113
141
  - Webhooks
114
142
  - Transformation create/get/update/delete/run/cancel/upgrade
@@ -148,25 +176,12 @@ Validate the generated artifacts:
148
176
  twine check dist/*
149
177
  ```
150
178
 
151
- Upload to TestPyPI first:
152
-
153
- ```bash
154
- twine upload --repository testpypi dist/*
155
- ```
156
-
157
- Install from TestPyPI in a clean environment:
158
-
159
- ```bash
160
- python3 -m pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ fivetran-cli
161
- fivetran --help
162
- ```
163
-
164
- Upload to PyPI after the TestPyPI package is verified:
179
+ Upload to PyPI:
165
180
 
166
181
  ```bash
167
182
  twine upload dist/*
168
183
  ```
169
184
 
170
- These upload commands assume `~/.pypirc` is configured with the `pypi` and `testpypi` repositories. If `~/.pypirc` is not configured, set `TWINE_USERNAME=__token__` and `TWINE_PASSWORD=<api-token>` before running `twine upload`.
185
+ This upload command assumes `~/.pypirc` is configured with the `pypi` repository. If `~/.pypirc` is not configured, set `TWINE_USERNAME=__token__` and `TWINE_PASSWORD=<api-token>` before running `twine upload`.
171
186
 
172
187
  PyPI files are immutable for a published version. If an upload is wrong, bump the version in `pyproject.toml`, rebuild, re-check, and upload the new version.
@@ -10,7 +10,7 @@ src/fivetran_cli/output.py
10
10
  src/fivetran_cli.egg-info/PKG-INFO
11
11
  src/fivetran_cli.egg-info/SOURCES.txt
12
12
  src/fivetran_cli.egg-info/dependency_links.txt
13
- src/fivetran_cli.egg-info/entry_points.txt
13
+ src/fivetran_cli.egg-info/requires.txt
14
14
  src/fivetran_cli.egg-info/top_level.txt
15
15
  tests/test_cli.py
16
16
  tests/test_client.py
@@ -0,0 +1 @@
1
+ fivetran-connector-sdk>=2.9.2
@@ -1,13 +1,17 @@
1
1
  from __future__ import annotations
2
2
 
3
+ import argparse
3
4
  import io
4
5
  import json
5
6
  import os
7
+ import sys
6
8
  import tempfile
9
+ import types
7
10
  import unittest
8
11
  from pathlib import Path
9
12
  from unittest.mock import patch
10
13
 
14
+ import fivetran_cli.cli as cli
11
15
  from fivetran_cli.cli import run
12
16
  from fivetran_cli.client import ClientConfig
13
17
 
@@ -262,6 +266,116 @@ class CliTests(unittest.TestCase):
262
266
  self.assertEqual(code, 0, stderr)
263
267
  self.assertEqual(client.calls[0][0:2], ("GET", "/v1/groups/group_id/public-key"))
264
268
 
269
+ def test_sdk_command_delegates_original_argv(self):
270
+ stdout = io.StringIO()
271
+ stderr = io.StringIO()
272
+ calls = []
273
+
274
+ def sdk_runner(argv):
275
+ calls.append(list(argv))
276
+ return 23
277
+
278
+ def factory(_config):
279
+ self.fail("REST client should not be created for SDK commands")
280
+
281
+ code = run(
282
+ ["deploy", "connector", "--api-key", "key"],
283
+ client_factory=factory,
284
+ sdk_runner=sdk_runner,
285
+ stdout=stdout,
286
+ stderr=stderr,
287
+ )
288
+
289
+ self.assertEqual(code, 23)
290
+ self.assertEqual(calls, [["deploy", "connector", "--api-key", "key"]])
291
+ self.assertEqual(stdout.getvalue(), "")
292
+ self.assertEqual(stderr.getvalue(), "")
293
+
294
+ def test_unknown_command_delegates_to_sdk_for_native_error_handling(self):
295
+ calls = []
296
+
297
+ code = run(
298
+ ["does-not-exist"],
299
+ client_factory=lambda _config: self.fail("REST client should not be created"),
300
+ sdk_runner=lambda argv: calls.append(list(argv)) or 9,
301
+ stdout=io.StringIO(),
302
+ stderr=io.StringIO(),
303
+ )
304
+
305
+ self.assertEqual(code, 9)
306
+ self.assertEqual(calls, [["does-not-exist"]])
307
+
308
+ def test_top_level_help_lists_connector_sdk_commands(self):
309
+ stdout = io.StringIO()
310
+ stderr = io.StringIO()
311
+
312
+ with patch(
313
+ "fivetran_cli.cli._sdk_command_help",
314
+ return_value=(
315
+ ("debug", "Run connector locally in debug mode."),
316
+ ("deploy", "Deploy connector to Fivetran."),
317
+ ),
318
+ ):
319
+ code = run(
320
+ ["-h"],
321
+ client_factory=lambda _config: self.fail("REST client should not be created"),
322
+ sdk_runner=lambda _argv: self.fail("SDK runner should not be called for top-level help"),
323
+ stdout=stdout,
324
+ stderr=stderr,
325
+ )
326
+
327
+ output = stdout.getvalue()
328
+ self.assertEqual(code, 0)
329
+ self.assertIn("positional arguments:", output)
330
+ self.assertIn("deploy", output)
331
+ self.assertIn("Deploy connector to Fivetran.", output)
332
+ self.assertIn("debug", output)
333
+ self.assertIn("Run connector locally in debug mode.", output)
334
+ self.assertIn("--version", output)
335
+ self.assertNotIn("Connector SDK commands:", output)
336
+ self.assertNotIn("connector-sdk-command", output)
337
+ self.assertEqual(stderr.getvalue(), "")
338
+
339
+ def test_sdk_command_help_reads_connector_sdk_parser_metadata(self):
340
+ sdk_package = types.ModuleType("fivetran_connector_sdk")
341
+ sdk_package.__path__ = []
342
+ cli_parser = types.ModuleType("fivetran_connector_sdk.cli_parser")
343
+
344
+ def create_argument_parser():
345
+ parser = argparse.ArgumentParser()
346
+ subparsers = parser.add_subparsers(dest="command")
347
+ subparsers.add_parser("ship", help="Ship connector.")
348
+ subparsers.add_parser("inspect", help="Inspect connector.")
349
+ return parser
350
+
351
+ cli_parser.create_argument_parser = create_argument_parser
352
+
353
+ with patch.dict(
354
+ sys.modules,
355
+ {
356
+ "fivetran_connector_sdk": sdk_package,
357
+ "fivetran_connector_sdk.cli_parser": cli_parser,
358
+ },
359
+ ):
360
+ self.assertEqual(
361
+ cli._sdk_command_help(),
362
+ (("ship", "Ship connector."), ("inspect", "Inspect connector.")),
363
+ )
364
+
365
+ def test_top_level_version_delegates_to_sdk(self):
366
+ calls = []
367
+
368
+ code = run(
369
+ ["--version"],
370
+ client_factory=lambda _config: self.fail("REST client should not be created"),
371
+ sdk_runner=lambda argv: calls.append(list(argv)) or 0,
372
+ stdout=io.StringIO(),
373
+ stderr=io.StringIO(),
374
+ )
375
+
376
+ self.assertEqual(code, 0)
377
+ self.assertEqual(calls, [["--version"]])
378
+
265
379
  def test_output_write_failure_is_user_facing_error(self):
266
380
  code, _, stderr, client = self.run_cli(
267
381
  [
@@ -346,7 +460,8 @@ class CliTests(unittest.TestCase):
346
460
  self.assertEqual(client.calls[0][0:2], ("GET", "/v1/metadata/connector-types/google_ads"))
347
461
 
348
462
  def test_public_connector_list_does_not_require_auth(self):
349
- code, _, stderr, client = self.run_cli(["public-connector", "list"])
463
+ with patch.dict(os.environ, {}, clear=True):
464
+ code, _, stderr, client = self.run_cli(["public-connector", "list"])
350
465
 
351
466
  self.assertEqual(code, 0, stderr)
352
467
  self.assertIsNone(client.config.api_key)
@@ -1,2 +0,0 @@
1
- [console_scripts]
2
- fivetran = fivetran_cli.cli:main
File without changes
File without changes
File without changes