option

package
v0.0.18 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 23, 2025 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BooleanUnfold

type BooleanUnfold struct {
	OptionTrue  string
	OptionFalse string
}

type RewriteAction

type RewriteAction func(schemas ast.Schemas, builder ast.Builder, option ast.Option) []ast.Option

func AddAssignmentAction

func AddAssignmentAction(assignment veneers.Assignment) RewriteAction

AddAssignmentAction adds an assignment to an existing option.

func AddCommentsAction added in v0.0.11

func AddCommentsAction(comments []string) RewriteAction

AddCommentsAction adds comments to an option.

func ArrayToAppendAction

func ArrayToAppendAction() RewriteAction

ArrayToAppendAction updates the option to perform an "append" assignment.

Example:

```
func Tags(tags []string) {
	this.resource.tags = tags
}
```

Will become:

```
func Tags(tags string) {
	this.resource.tags.append(tags)
}
```

This action returns the option unchanged if:

  • it doesn't have exactly one argument
  • the argument is not an array

func DisjunctionAsOptionsAction

func DisjunctionAsOptionsAction() RewriteAction

DisjunctionAsOptionsAction uses the branches of the first argument's disjunction (assuming it is one) and turns them into options.

Example:

```
func Panel(panel Panel|Row) {
	this.resource.panels.append(panel)
}
```

Will become:

```
func Panel(panel Panel) {
	this.resource.panels.append(panel)
}

func Row(row Row) {
	this.resource.panels.append(row)
}
```

This action returns the option unchanged if:

  • it has no arguments
  • the first argument is not a disjunction or a reference to one

FIXME: considers the first argument only.

func DuplicateAction

func DuplicateAction(duplicateName string) RewriteAction

func MapToIndexAction added in v0.0.8

func MapToIndexAction() RewriteAction

MapToIndexAction updates the option to perform an "index" assignment.

Example:

```
func Elements(elements map[string]Element) {
	this.resource.elements = elements
}
```

Will become:

```
func Elements(key string, elements Element) {
	this.resource.elements[key] = tags
}
```

This action returns the option unchanged if:

  • it doesn't have exactly one argument
  • the argument is not a map

func OmitAction

func OmitAction() RewriteAction

OmitAction removes an option.

func RenameAction

func RenameAction(newName string) RewriteAction

RenameAction renames an option.

func RenameArgumentsAction

func RenameArgumentsAction(newNames []string) RewriteAction

RenameArgumentsAction renames the arguments of an options.

func StructFieldsAsArgumentsAction

func StructFieldsAsArgumentsAction(explicitFields ...string) RewriteAction

StructFieldsAsArgumentsAction uses the fields of the first argument's struct (assuming it is one) and turns them into arguments.

Optionally, an explicit list of fields to turn into arguments can be given.

Example:

```
func Time(time {from string, to string) {
	this.resource.time = time
}
```

Will become:

```
func Time(from string, to string) {
	this.resource.time.from = from
	this.resource.time.to = to
}
```

This action returns the option unchanged if:

  • it has no arguments
  • the first argument is not a struct or a reference to one

FIXME: considers the first argument only.

func StructFieldsAsOptionsAction

func StructFieldsAsOptionsAction(explicitFields ...string) RewriteAction

StructFieldsAsOptionsAction uses the fields of the first argument's struct (assuming it is one) and turns them into options.

Optionally, an explicit list of fields to turn into options can be given.

Example:

```
func GridPos(gridPos {x int, y int) {
	this.resource.gridPos = gridPos
}
```

Will become:

```
func X(x int) {
	this.resource.gridPos.x = x
}

func Y(y int) {
	this.resource.gridPos.y = y
}
```

This action returns the option unchanged if:

  • it has no arguments
  • the first argument is not a struct or a reference to one

FIXME: considers the first argument only.

func UnfoldBooleanAction

func UnfoldBooleanAction(unfoldOpts BooleanUnfold) RewriteAction

UnfoldBooleanAction transforms an option accepting a boolean argument into two argument-less options.

Example:

```
func Editable(editable bool) {
	this.resource.editable = editable
}
```

Will become:

```
func Editable() {
	this.resource.editable = true
}

func ReadOnly() {
	this.resource.editable = false
}
```

func VeneerTrailAsCommentsAction

func VeneerTrailAsCommentsAction() RewriteAction

VeneerTrailAsCommentsAction removes an option.

type RewriteRule

type RewriteRule struct {
	Selector Selector
	Action   RewriteAction
}

func AddAssignment

func AddAssignment(selector Selector, assignment veneers.Assignment) RewriteRule

func AddComments added in v0.0.11

func AddComments(selector Selector, comments []string) RewriteRule

func ArrayToAppend

func ArrayToAppend(selector Selector) RewriteRule

func DisjunctionAsOptions

func DisjunctionAsOptions(selector Selector) RewriteRule

func Duplicate

func Duplicate(selector Selector, duplicateName string) RewriteRule

func MapToIndex added in v0.0.8

func MapToIndex(selector Selector) RewriteRule

func Omit

func Omit(selector Selector) RewriteRule

func Rename

func Rename(selector Selector, newName string) RewriteRule

func RenameArguments

func RenameArguments(selector Selector, newNames []string) RewriteRule

func StructFieldsAsArguments

func StructFieldsAsArguments(selector Selector, explicitFields ...string) RewriteRule

func StructFieldsAsOptions

func StructFieldsAsOptions(selector Selector, explicitFields ...string) RewriteRule

func UnfoldBoolean

func UnfoldBoolean(selector Selector, unfoldOpts BooleanUnfold) RewriteRule

func VeneerTrailAsComments

func VeneerTrailAsComments(selector Selector) RewriteRule

type Selector

type Selector func(builder ast.Builder, option ast.Option) bool

func ByBuilder

func ByBuilder(pkg string, builderName string, optionNames ...string) Selector

ByBuilder matches options by their name and the name of the builder containing them.. Note: the comparison on builder and options names is case-insensitive.

func ByName

func ByName(pkg string, objectName string, optionNames ...string) Selector

ByName matches options by their name, defined for builders for the given object (referred to by its package and name). Note: the comparison on object and options names is case-insensitive.

func EveryOption

func EveryOption() Selector

EveryOption accepts any given option.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL