Skip to content

Commit

Permalink
Merge branch 'RSDK-9204-experimental' into remove-webcam-logic
Browse files Browse the repository at this point in the history
  • Loading branch information
hexbabe authored Jan 29, 2025
2 parents a00c1bc + 507d40d commit 2d5cf42
Show file tree
Hide file tree
Showing 126 changed files with 5,295 additions and 1,995 deletions.
3 changes: 3 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Team SDK is responsible for CLI best practices and wishes to maintain insight into any
# changes currently being made to the CLI codebase.
/cli/app.go @viamrobotics/sdk-netcode
/cli/CONTRIBUTING.md @viamrobotics/sdk-netcode
/cli/STYLEGUIDE.md @viamrobotics/sdk-netcode

2 changes: 1 addition & 1 deletion .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ jobs:

test:
needs: docker-cache
uses: viamrobotics/rdk/.github/workflows/test.yml@main
uses: ./.github/workflows/test.yml
secrets:
MONGODB_TEST_OUTPUT_URI: ${{ secrets.MONGODB_TEST_OUTPUT_URI }}
DOCKER_PUBLIC_READONLY_PAT: ${{ secrets.DOCKER_PUBLIC_READONLY_PAT }}
12 changes: 9 additions & 3 deletions .github/workflows/staticbuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,15 @@ jobs:
- arch: ubuntu-latest
image: ghcr.io/viamrobotics/antique2:amd64-cache
platform: linux/amd64
target: static-release
- arch: ubuntu-small-arm
image: ghcr.io/viamrobotics/antique2:arm64-cache
platform: linux/arm64
target: static-release
- arch: ubuntu-latest
image: ghcr.io/viamrobotics/antique2:amd64-cache
platform: linux/amd64
target: static-release-win
runs-on: ${{ matrix.arch }}
container:
image: ${{ matrix.image }}
Expand Down Expand Up @@ -89,7 +95,7 @@ jobs:
- name: Build (PR)
if: contains(github.event.pull_request.labels.*.name, 'static-build') || contains(github.event.pull_request.labels.*.name, 'static-ignore-tests')
run: |
sudo -Hu testbot bash -lc 'make BUILD_CHANNEL="pr-${{ github.event.pull_request.number }}" static-release'
sudo -Hu testbot bash -lc 'make BUILD_CHANNEL="pr-${{ github.event.pull_request.number }}" ${{ matrix.target }}'
- name: Upload Files (PR)
if: contains(github.event.pull_request.labels.*.name, 'static-build') || contains(github.event.pull_request.labels.*.name, 'static-ignore-tests')
Expand All @@ -105,12 +111,12 @@ jobs:
- name: Build (Latest)
if: inputs.release_type == 'latest'
run: |
sudo -Hu testbot bash -lc 'make RELEASE_TYPE="latest" BUILD_CHANNEL="${{needs.build_timestamp.outputs.date}}" static-release'
sudo -Hu testbot bash -lc 'make RELEASE_TYPE="latest" BUILD_CHANNEL="${{needs.build_timestamp.outputs.date}}" ${{ matrix.target }}'
- name: Build (Tagged)
if: inputs.release_type == 'stable' || inputs.release_type == 'rc'
run: |
sudo -Hu testbot bash -lc 'make RELEASE_TYPE="${{ inputs.release_type }}" BUILD_CHANNEL="${{ github.ref_name }}" static-release'
sudo -Hu testbot bash -lc 'make RELEASE_TYPE="${{ inputs.release_type }}" BUILD_CHANNEL="${{ github.ref_name }}" ${{ matrix.target }}'
- name: Set Date
id: build_date
Expand Down
45 changes: 22 additions & 23 deletions .github/workflows/test-module-generation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,29 @@ jobs:
language: ["python", "go"]
resource:
[
{ subtype: "arm", type: "component" },
{ subtype: "audio_input", type: "component" },
{ subtype: "base", type: "component" },
{ subtype: "board", type: "component" },
{ subtype: "camera", type: "component" },
{ subtype: "encoder", type: "component" },
{ subtype: "gantry", type: "component" },
{ subtype: "generic", type: "component" },
{ subtype: "gripper", type: "component" },
{ subtype: "input", type: "component" },
{ subtype: "motor", type: "component" },
{ subtype: "movement_sensor", type: "component" },
{ subtype: "pose_tracker", type: "component" },
{ subtype: "power_sensor", type: "component" },
{ subtype: "sensor", type: "component" },
{ subtype: "servo", type: "component" },
{ subtype: "arm" },
{ subtype: "audio_input" },
{ subtype: "base" },
{ subtype: "board" },
{ subtype: "camera" },
{ subtype: "encoder" },
{ subtype: "gantry" },
{ subtype: "generic_component" },
{ subtype: "gripper" },
{ subtype: "input" },
{ subtype: "motor" },
{ subtype: "movement_sensor" },
{ subtype: "pose_tracker" },
{ subtype: "power_sensor" },
{ subtype: "sensor" },
{ subtype: "servo" },

{ subtype: "generic", type: "service" },
{ subtype: "mlmodel", type: "service" },
{ subtype: "motion", type: "service" },
{ subtype: "navigation", type: "service" },
{ subtype: "slam", type: "service" },
{ subtype: "vision", type: "service" },
{ subtype: "generic-service" },
{ subtype: "mlmodel" },
{ subtype: "motion" },
{ subtype: "navigation" },
{ subtype: "slam" },
{ subtype: "vision" },
]
steps:
- name: Checkout Code
Expand All @@ -53,7 +53,6 @@ jobs:
--language "${{ matrix.language }}" \
--public-namespace "my-org" \
--resource-subtype "${{ matrix.resource.subtype }}" \
--resource-type "${{ matrix.resource.type }}" \
--model-name "model-name" \
--dry-run
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ jobs:
- name: Run go unit tests
run: |
chmod -R a+rwx . # temporary fix for arm runners
sudo apt-get install -y python3-venv
sudo apt-get update && sudo apt-get install -y python3-venv
sudo --preserve-env=MONGODB_TEST_OUTPUT_URI,GITHUB_SHA,GITHUB_RUN_ID,GITHUB_RUN_NUMBER,GITHUB_RUN_ATTEMPT,GITHUB_X_PR_BASE_SHA,GITHUB_X_PR_BASE_REF,GITHUB_X_HEAD_REF,GITHUB_X_HEAD_SHA,GITHUB_REPOSITORY -Hu testbot bash -lc 'make test-go'
- name: Upload test.json
Expand Down Expand Up @@ -108,7 +108,7 @@ jobs:
--platform linux/arm/v7 \
-v `pwd`:/rdk \
ghcr.io/viamrobotics/rdk-devenv:armhf-cache \
sudo -Hu testbot bash -lc 'sudo apt-get install -y python3-venv && cd /rdk && go test -v ./...'
sudo -Hu testbot bash -lc 'sudo apt-get update && sudo apt-get install -y python3-venv && cd /rdk && go test -v ./...'
motion_tests:
name: Test Longer-running Motion Plans if affected
Expand Down
55 changes: 55 additions & 0 deletions cli/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Contributing

Contributions to the Viam CLI are always welcome and appreciated! Every bit helps, and
credit will always be given.

## Types of Contributions

### Report Bugs

If you are reporting a bug, please include:

- Your operating system name and version.
- Which version of the viam CLI you are using (viewable with command `viam version`)
- Any details about your local setup that might be helpful in troubleshooting.
- The observed behavior.
- Detailed steps to reproduce the bug.

### Fix Bugs

Look through the GitHub issues for bugs. Anything tagged with "bug" and "help
wanted" is open to whoever wants to implement it.

### Implement Features

Look through the GitHub issues for features. Anything tagged with "enhancement"
and "help wanted" is open to whoever wants to implement it. When contributing, please
consult the [style guide](STYLEGUIDE.md) to ensure consistency within the codebase.

### Write Documentation

You can never have enough documentation! Please feel free to contribute to any
part of the documentation, such as the official docs, docstrings, or even
on the web in blog posts, articles, and such.

### Submit Feedback

If you are proposing a feature:

- Explain in detail how it would work.
- Keep the scope as narrow as possible, to make it easier to implement.

## Get Started!

Ready to contribute? You can follow the instructions in [README.md](README.md) to install and develop
the viam CLI tool.

## Pull Request Guidelines

Before you submit a pull request, check that it meets these guidelines:

1. The pull request should include additional tests if appropriate.
2. If the pull request adds functionality, the docs should be updated.
3. The pull request should work for all currently supported operating systems and versions of Python.


188 changes: 188 additions & 0 deletions cli/STYLEGUIDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
# Code Style

Thank you for contributing to the Viam CLI! Please keep in mind the following best practices
when structuring your code.

## Make Arguments Typeful
Your CLI command's action func should be constructed with `createCommandWithT` and should put
all command line argument values in a typed struct. This ensures type correctness and reduces
the risks associated with having contributors manually parse args in each function they write.

### Examples
<details>
<summary>Good:</summary>

```golang
type fooArgs struct {
Bar int
Baz string
}

func fooAction(ctx cli.Context, args foo) error {
bar := args.Bar
baz := args.Baz
...
}

...

cli.Command{
...
Flags: []cli.Flag{
&cli.StringFlag{
Name: Baz,
},
&cli.IntFlag{
Name: Bar,
},
},
Action: createCommandWithT[fooArgs](fooAction),
...
}
```
</details>

<details>
<summary>Bad:</summary>

```golang
func fooAction(ctx cli.Context) error {
bar := ctx.Int("Bar")
baz := ctx.String("Baz)
...
}
...
cli.Command{
Flags: []cli.Flag{
&cli.StringFlag{
Name: BazFlag,
},
&cli.IntFlag{
Name: BarFlag,
},
},
Action: fooAction,
...
}
```
</details>
## Avoid Flag Bloat
We have a significant number of flags in the CLI already, many of which (e.g., `organization` or
`location`) are used in multiple functions. Instead of adding duplicate flags, prefer reusing
existing flags. If necessary, rename then to indicate their more generic usage.
### Example
<details>
<summary>Good:</summary>
```diff
-const yourSpecialFlag = "some-cool-flag"
+const generalSpecialFlag = "some-cool-flag"
```
</details>
<details>
<summary>Bad:</summary>
```golang
const yourSpecialFlag = "some-cool-flag"
...
const mySpecialFlag = "some-cool-flag"
```
</details>
## Hide Help From Commands With Subcommands
When a parent level command with child commands exists (e.g., `viam organizations` has `list`,
`logo`, `api-key`, and others as child commands), it makes little sense to show a `help` command
since the parent level command doesn't do anything on its own.
### Example
<details>
<summary>Necessary diff:</summary>
```diff
cli.Command{
...
Name: "my-parent-command",
+ HideHelpCommand: true,
Subcommands: []*cli.Command{
{
Name: "my-child-command1",
...
},
{
Name: "my-child-command2",
...
},
},
}
```
</details>
## Create Usage Text With Helper Func, Only Specify Required Args
When creating usage text for a CLI command, use the `createUsageText` convenience method
to generate text. Be sure to provide the fully qualified command (less `viam`) as your first
argument, and only include actually required flags in the `requiredFlags` argument.
Additionally, be sure to use the `formatAcceptedValues` convenience method for defining usage
text on a flag where only a discrete set of values are permitted.
### Example
<details>
<summary>Diff:</summary>
```diff
cli.Command{
...
Name: "my-parent-command",
Subcommands: []*cli.Command{
Name: "my-child-command",
Flags: []cli.Flag{
&cli.StringFlag{
Name: requiredFlag,
Required: true,
+ Usage: formatAcceptedValues("passes some required value", 'foo', 'bar, 'baz')
- Usage: "passes some required value. must be either 'foo', 'bar', or 'baz'"
},
&cli.StringFlag{
Name: optionalFlag,
},
},
+ UsageText: createUsageText("my-parent-command my-child-command", []string{requiredFlag}, true, false),
- UsageText: createUsageText("my-child-command", []string{requiredFlag, optionalFlag}, false, false),
...
}
}
```
</details>
## Use `DefaultText` Field For Defining Default values
Instead of adding extra text to the description of what a field does, we should use the automated
formatting provided by the `DefaultText` field.
### Examples
<details>
<summary>Good:</summary>
```golang
cli.StringFlag{
Name: fooFlag,
Usage: "sets value of Foo",
DefaultText: "foo",
}
```
</details>
<details>
<summary>Bad:</summary>
```golang
cli.StringFlag{
Name: fooFlag,
Usage: "sets value of Foo (defaults to foo)",
}
```
</details>
Loading

0 comments on commit 2d5cf42

Please sign in to comment.