Skip to main content

Scripting ORAS in Go

It is possible to use the ORAS CLI in Go scripts. When you are scripting ORAS in Go, the parameters should be specified just like they are on the command line.

For example:

package main
import (
func main() {
// change below array to play with your own cmd args:
args := []string{"repo", "ls", ""}
cmd := root.New()
fmt.Printf("Executing 'oras %s':", strings.Join(args, " "))
err := cmd.Execute()
if err != nil {
fmt.Errorf("Failed to execute : %w", err)

To run this example:

mkdir example
cd example
go mod init example
go mod edit --require
# copy the example code into the directory...
cat >main.go
go mod tidy
go run main.go