Skip to content

Commit 95e7515

Browse files
authored
Merge pull request #56 from maysunfaisal/updateReadme-2
Provide code snippets in ReadMe
2 parents ae471a9 + 83266df commit 95e7515

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

README.md

+24-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,30 @@ The Devfile Parser library is a Golang module that:
99
4. defines util functions for the devfile.
1010

1111
The function documentation can be accessed via [pkg.go.dev](https://pkg.go.dev/github.com/devfile/library).
12-
1. To parse a devfile, visit pkg/devfile/parse.go
13-
2. To get the Kubernetes structs from the devfile, visit pkg/devfile/generator/generators.go
12+
1. To parse a devfile, visit pkg/devfile/parse.go
13+
```
14+
// Parses the devfile and validates the devfile data
15+
devfile, err := devfilePkg.ParseAndValidate(devfileLocation)
16+
17+
// To get all the components from the devfile
18+
components, err := devfile.Data.GetComponents(DevfileOptions{})
19+
```
20+
2. To get the Kubernetes objects from the devfile, visit pkg/devfile/generator/generators.go
21+
```
22+
// To get a slice of Kubernetes containers of type corev1.Container from the devfile component containers
23+
containers, err := generator.GetContainers(devfile)
24+
25+
// To generate a Kubernetes deployment of type v1.Deployment
26+
deployParams := generator.DeploymentParams{
27+
TypeMeta: generator.GetTypeMeta(deploymentKind, deploymentAPIVersion),
28+
ObjectMeta: generator.GetObjectMeta(name, namespace, labels, annotations),
29+
InitContainers: initContainers,
30+
Containers: containers,
31+
Volumes: volumes,
32+
PodSelectorLabels: labels,
33+
}
34+
deployment := generator.GetDeployment(deployParams)
35+
```
1436
1537
## Usage
1638

0 commit comments

Comments
 (0)