Skip to content

Commit 80be82d

Browse files
feat: Add fig support to Meroxa CLI (#403)
* feat: Add fig support * feat: add workflow * feat: generate fig documentation separately * test: workflow * rename: acceptance test action * update: gh action * fix: update gh action name * add debugger * move action * Test new spec path * update spec path * test direct push * fix: description for apps deploy * fix: update documentation + workflow * feat: update spec only when releasing * fix: isRepeatable * chore: Update dependencies * chore: Update documentation that was out of date * doc: Update readme adding steps relevant to Fig * chore: no need to delete it * fix: typo * Update gen-spec/main.go Co-authored-by: Janelle Tavares <janelletavares@users.noreply.github.com> * Update gen-spec/main.go Co-authored-by: Janelle Tavares <janelletavares@users.noreply.github.com> * fix: link * fix: lint * chore: update fig spec Co-authored-by: Janelle Tavares <janelletavares@users.noreply.github.com>
1 parent c5783c0 commit 80be82d

File tree

158 files changed

+6385
-1640
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

158 files changed

+6385
-1640
lines changed

.github/workflows/pull_request.yml .github/workflows/acceptance_test.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
name: Acceptance Test
2-
1+
name: Acceptance Tests
32
# Run this workflow every time a new PR wants to merge to master/main
43
on:
54
pull_request:

.github/workflows/fig.yml

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: 'Fig Autocomplete Spec'
2+
on:
3+
push:
4+
tags:
5+
- 'v*'
6+
- '!v*.*.*-nightly.*'
7+
workflow_dispatch:
8+
9+
jobs:
10+
publish-spec:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Set up Go
14+
uses: actions/setup-go@v3
15+
with:
16+
go-version: ^1.18
17+
- name: Check out code into the Go module directory
18+
uses: actions/checkout@v3
19+
- name: Run make fig
20+
run: |
21+
make fig
22+
- name: Create Autocomplete PR ## Create the autocomplete PR using this action
23+
uses: withfig/push-to-fig-autocomplete-action@v1
24+
with:
25+
token: ${{ secrets.MEROXA_MACHINE }}
26+
autocomplete-spec-name: meroxa
27+
spec-path: spec/meroxa.ts
28+
repo-org: meroxa
29+
repo-name: cli-autocomplete
30+
integration: cobra
31+
use-minor-base: true

Makefile

+5-1
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,17 @@ test:
2424
go test -v ${GO_TEST_FLAGS} -count=1 -timeout 5m ./...
2525

2626
.PHONY: docs
27-
docs:
2827
ifeq ($(REBUILD_DOCS), "true")
28+
docs:
2929
rm -rf docs/cmd && mkdir -p docs/cmd/{md,www}
3030
rm -rf etc && mkdir -p etc/man/man1 && mkdir -p etc/completion
3131
go run gen-docs/main.go
3232
endif
3333

34+
.PHONY: fig
35+
fig:
36+
go run gen-spec/main.go
37+
3438
.PHONY: lint
3539
lint:
3640
docker run --rm -v $(CURDIR):/app -w /app golangci/golangci-lint:latest golangci-lint run --timeout 5m -v

README.md

+10
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ These are also updated when running `make build`. In the event you need to build
3232
$ export REBUILD_DOCS="false"
3333
```
3434

35+
To generate manually a Meroxa spec for Fig, you could simply run:
36+
37+
```shell
38+
$ make fig
39+
```
40+
3541
## Contributing
3642

3743
For a complete guide to contributing to the Meroxa CLI, see the [Contribution Guide](CONTRIBUTING.md).
@@ -81,6 +87,10 @@ git tag is pushed to the repo.
8187

8288
With every release, a new Homebrew formula will be automatically updated on [meroxa/homebrew-taps](https://github.com/meroxa/homebrew-taps).
8389

90+
When releasing a newer version of our Meroxa CLI, a new [Meroxa spec](https://github.com/withfig/autocomplete/blob/master/src/meroxa.ts) for [Fig](https://fig.io/) will be automatically generated in [meroxa/cli-autocomplete](https://github.com/meroxa/cli-autocomplete) via [this GitHub action](/.github/workflows/fig.yml).
91+
92+
Once a new pull-request is opened in [meroxa/cli-autocomplete](https://github.com/meroxa/cli-autocomplete), you'll need to submit a request to main's [withfig/autocomplete's](https://github.com/withfig/autocomplete) repository.
93+
8494
## Linting
8595

8696
If you want to make sure everything's correct before pushing to GitHub, you'll need to install [`golangci-lint`](https://golangci-lint.run/) and run:

cmd/meroxa/root/apps/deploy.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ type deployApplicationClient interface {
6262

6363
type Deploy struct {
6464
flags struct {
65-
Path string `long:"path" description:"path to the app directory (default is local directory)"`
66-
DockerHubUserName string `long:"docker-hub-username" description:"DockerHub username to use to build and deploy the app" hidden:"true"` //nolint:lll
67-
DockerHubAccessToken string `long:"docker-hub-access-token" description:"DockerHub access token to use to build and deploy the app" hidden:"true"` //nolint:lll
68-
Spec string `long:"spec" description:"Deployment specification version to use to build and deploy the app" hidden:"true"`
65+
Path string `long:"path" usage:"path to the app directory (default is local directory)"`
66+
DockerHubUserName string `long:"docker-hub-username" usage:"DockerHub username to use to build and deploy the app" hidden:"true"` //nolint:lll
67+
DockerHubAccessToken string `long:"docker-hub-access-token" usage:"DockerHub access token to use to build and deploy the app" hidden:"true"` //nolint:lll
68+
Spec string `long:"spec" usage:"Deployment specification version to use to build and deploy the app" hidden:"true"`
6969
}
7070

7171
client deployApplicationClient

cmd/meroxa/root/root.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ meroxa resources list --types
7878
global.RegisterGlobalFlags(cmd)
7979

8080
// Subcommands
81-
cmd.AddCommand(CompletionCmd()) // Coming from Cobra
81+
cmd.AddCommand(CompletionCmd()) // To generate shell autocompletion
8282

8383
cmd.AddCommand(builder.BuildCobraCommand(&api.API{}))
8484
cmd.AddCommand(builder.BuildCobraCommand(&auth.Auth{}))

docs/cmd/md/meroxa_apps_deploy.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ meroxa apps deploy --path ./my-app
2525

2626
```
2727
-h, --help help for deploy
28-
--path string
28+
--path string path to the app directory (default is local directory)
2929
```
3030

3131
### Options inherited from parent commands

docs/cmd/www/meroxa-apps-deploy.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ meroxa apps deploy --path ./my-app
3232

3333
```
3434
-h, --help help for deploy
35-
--path string
35+
--path string path to the app directory (default is local directory)
3636
```
3737

3838
### Options inherited from parent commands

etc/completion/meroxa.completion.fish

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ function __meroxa_perform_completion
1818
__meroxa_debug "args: $args"
1919
__meroxa_debug "last arg: $lastArg"
2020

21-
set -l requestComp "$args[1] __complete $args[2..-1] $lastArg"
21+
# Disable ActiveHelp which is not supported for fish shell
22+
set -l requestComp "MEROXA_ACTIVE_HELP=0 $args[1] __complete $args[2..-1] $lastArg"
2223

2324
__meroxa_debug "Calling $requestComp"
2425
set -l results (eval $requestComp 2> /dev/null)

etc/completion/meroxa.completion.ps1

+7-4
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,18 @@ Register-ArgumentCompleter -CommandName 'meroxa' -ScriptBlock {
3333
if ($Command.Length -gt $CursorPosition) {
3434
$Command=$Command.Substring(0,$CursorPosition)
3535
}
36-
__meroxa_debug "Truncated command: $Command"
36+
__meroxa_debug "Truncated command: $Command"
3737

3838
$ShellCompDirectiveError=1
3939
$ShellCompDirectiveNoSpace=2
4040
$ShellCompDirectiveNoFileComp=4
4141
$ShellCompDirectiveFilterFileExt=8
4242
$ShellCompDirectiveFilterDirs=16
4343

44-
# Prepare the command to request completions for the program.
44+
# Prepare the command to request completions for the program.
4545
# Split the command at the first space to separate the program and arguments.
4646
$Program,$Arguments = $Command.Split(" ",2)
47+
4748
$RequestComp="$Program __completeNoDesc $Arguments"
4849
__meroxa_debug "RequestComp: $RequestComp"
4950

@@ -73,11 +74,13 @@ Register-ArgumentCompleter -CommandName 'meroxa' -ScriptBlock {
7374
}
7475

7576
__meroxa_debug "Calling $RequestComp"
77+
# First disable ActiveHelp which is not supported for Powershell
78+
$env:MEROXA_ACTIVE_HELP=0
79+
7680
#call the command store the output in $out and redirect stderr and stdout to null
7781
# $Out is an array contains each line per element
7882
Invoke-Expression -OutVariable out "$RequestComp" 2>&1 | Out-Null
7983

80-
8184
# get directive from last line
8285
[int]$Directive = $Out[-1].TrimStart(':')
8386
if ($Directive -eq "") {
@@ -216,7 +219,7 @@ Register-ArgumentCompleter -CommandName 'meroxa' -ScriptBlock {
216219
Default {
217220
# Like MenuComplete but we don't want to add a space here because
218221
# the user need to press space anyway to get the completion.
219-
# Description will not be shown because thats not possible with TabCompleteNext
222+
# Description will not be shown because that's not possible with TabCompleteNext
220223
[System.Management.Automation.CompletionResult]::new($($comp.Name | __meroxa_escapeStringWithSpecialChars), "$($comp.Name)", 'ParameterValue', "$($comp.Description)")
221224
}
222225
}

0 commit comments

Comments
 (0)