Commit Graph

3 Commits

Author SHA1 Message Date
Serge Smertin a686542b1f
(PoC) `Databricks Labs` command group
Allow for `labs.yml` definition in target repositories:

```
---
name: dbx
context: workspace
description: Databricks CLI extensions
hooks:
  install: install.py
entrypoint: main.py
commands:
  - name: foo
    description: foo command
    flags:
      - name: first
        description: first flag description
      - name: second
        description: second flag description
  - name: bar
    description: bar command
    flags:
      - name: first
        description: first flag description
      - name: second
        description: second flag description
```

and simple command entry points that are aware of both CLI flags and Unified Authentication env variables:

```
import os, sys, json

print(f'host is {os.environ["DATABRICKS_HOST"]}')

payload = json.loads(sys.argv[1])
print(f'[{payload["command"]}]: flags are {payload["flags"]}')

answer = input('What is your name? ')

print(f'got answer: {answer}')

answer = input('Preferences? ')

print(f'got answer: {answer}')
```
2023-08-05 18:06:50 +02:00
Pieter Noordhuis bee7a16cb0
Remove dependency on global state for remaining commands (#613)
## Changes

This removes the remaining dependency on global state and unblocks work
to parallelize integration tests. As is, we can already uncomment an
integration test that had to be skipped because of other tests tainting
global state. This is no longer an issue.

Also see #595 and #606.

## Tests

* Unit and integration tests pass.
* Manually confirmed the help output is the same.
2023-07-27 10:03:08 +00:00
Pieter Noordhuis 3fa400f00f
Remove dependency on global state in generated commands (#595)
## Changes

Generated commands relied on global variables for flags and request
payloads. This is difficult to test if a sequence of tests tries to run
the same command with various arguments because the global state causes
test interference. Moreover, it is impossible to run tests in parallel.

This change modifies the approach and turns every command group and
command itself into a function that returns a `*cobra.Command`. All
flags and request payloads are variables scoped to the command's
initialization function. This means it is possible to construct
independent copies of the CLI structure and fixes the test isolation
issue.

The scope of this change is only the generated commands. The other
commands will be changed accordingly in subsequent changes.

## Tests

Unit and integration tests pass.
2023-07-25 20:19:07 +02:00