Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: updating contributing resources/dev docs #439

Merged
merged 1 commit into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions docs/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,21 @@ The underlying library that drives the bulk of this tool is [libnuke](https://gi
has tooling to help generate documentation for a resource. Primary the library focuses on inspecting the resource struct
and generating documentation based on the fields of the struct for properties.

There's an additional sub command called `generate-resource-docs` that is hidden from standard usage. This command is
used to generate documentation for a resource and write it to disk. This command leverages the struct inspection to get
details about the properties and intertwine them with the markdown template to generate the documentation.
There's an additional tool called `generate-docs`. This command is used to generate documentation for a resource and
write it to disk. This command leverages the struct inspection to get details about the properties and intertwine them
with the markdown template to generate the documentation.

However, for this to work the resource needs to be updated to export all it's fields. This is done by capitalizing the
first letter of the field name. The field name should match what the existing property name is if it is defined.

#### Generating Documentation for All Resources

```console
go run tools/generate-docs/main.go --write
```

#### Generating Documentation for a Single Resource

```console
go run tools/generate-docs/main.go --resource EC2Instance --write
```
47 changes: 25 additions & 22 deletions docs/resources.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,35 +27,40 @@ It can optionally have the following methods defined:
package resources

import (
"context"
"github.com/ekristen/libnuke/pkg/resource"
"github.com/ekristen/libnuke/pkg/types"
"context"

"github.com/ekristen/libnuke/pkg/resource"
"github.com/ekristen/libnuke/pkg/types"

"github.com/ekristen/aws-nuke/v3/pkg/nuke"
"github.com/ekristen/aws-nuke/v3/pkg/nuke"
)

type ExampleResource struct {
ID *string
ID *string `description:"The ID of the resource"`
}

func (r *ExampleResource) Remove(_ context.Context) error {
// remove the resource, an error will put the resource in failed state
// resources in failed state are retried a number of times
return nil
// remove the resource, an error will put the resource in failed state
// resources in failed state are retried a number of times
return nil
}

func (r *ExampleResource) Filter() error {
// filter the resource, this is useful for built-in resources that cannot
// be removed, like an AWS managed resource, return an error here to filter
// it before it even gets to the user supplied filters.
return nil
// filter the resource, this is useful for built-in resources that cannot
// be removed, like an AWS managed resource, return an error here to filter
// it before it even gets to the user supplied filters.
return nil
}

func (r *ExampleResource) String() string {
// return a string representation of the resource, this is legacy, but still
// used for a number of reasons.
return *r.ID
// return a string representation of the resource, this is legacy, but still
// used for a number of reasons.
return *r.ID
}

func (r *ExampleResource) Properties() types.Properties {
// return a properties representation of the resource via struct inspection
return types.NewPropertiesFromStruct(r)
}
```

Expand Down Expand Up @@ -116,7 +121,7 @@ func (l *ExampleResourceLister) List(_ context.Context, o interface{}) ([]resour
// -----------------------------------------------------------------------------

type ExampleResource struct {
ID *string
ID *string `description:"The unique ID of the resource"`
}

func (r *ExampleResource) Remove(_ context.Context) error {
Expand All @@ -139,10 +144,8 @@ func (r *ExampleResource) String() string {
}

func (r *ExampleResource) Properties() types.Properties {
// return a properties representation of the resource
props := types.NewProperties()
props.Set("ID", r.ID)
return props
// return a properties representation of the resource from struct inspection
return types.NewPropertiesFromStruct(r)
}
```

Expand Down Expand Up @@ -279,7 +282,7 @@ func init() {

type SNSTopic struct {
svc *sns.SNS
TopicARN *string
TopicARN *string `description:"The ARN of the SNS Topic"`
Tags []*sns.Tag
}

Expand Down
Loading