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

Provide code snippets in ReadMe #56

Merged
merged 1 commit into from
Feb 3, 2021
Merged
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
26 changes: 24 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,30 @@ The Devfile Parser library is a Golang module that:
4. defines util functions for the devfile.

The function documentation can be accessed via [pkg.go.dev](https://pkg.go.dev/github.com/devfile/library).
1. To parse a devfile, visit pkg/devfile/parse.go
2. To get the Kubernetes structs from the devfile, visit pkg/devfile/generator/generators.go
1. To parse a devfile, visit pkg/devfile/parse.go
```
// Parses the devfile and validates the devfile data
devfile, err := devfilePkg.ParseAndValidate(devfileLocation)

// To get all the components from the devfile
components, err := devfile.Data.GetComponents(DevfileOptions{})
```
2. To get the Kubernetes objects from the devfile, visit pkg/devfile/generator/generators.go
```
// To get a slice of Kubernetes containers of type corev1.Container from the devfile component containers
containers, err := generator.GetContainers(devfile)

// To generate a Kubernetes deployment of type v1.Deployment
deployParams := generator.DeploymentParams{
TypeMeta: generator.GetTypeMeta(deploymentKind, deploymentAPIVersion),
ObjectMeta: generator.GetObjectMeta(name, namespace, labels, annotations),
InitContainers: initContainers,
Containers: containers,
Volumes: volumes,
PodSelectorLabels: labels,
}
deployment := generator.GetDeployment(deployParams)
```

## Usage

Expand Down