Skip to content

Commit

Permalink
add runnable example and exclude root package
Browse files Browse the repository at this point in the history
Signed-off-by: Billy Zha <jinzha1@microsoft.com>
  • Loading branch information
qweeah committed Feb 21, 2023
1 parent e6c5130 commit 8675b62
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
5 changes: 4 additions & 1 deletion .github/.codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ coverage:
status:
project:
default:
target: 60%
target: 60%

ignore:
- "cmd/oras/root"
36 changes: 36 additions & 0 deletions cmd/oras/root/example_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
Copyright The ORAS Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package root_test

import (
"fmt"
"os"
"strings"
)

// Example gives playable snippets of using oras CLI in command-line scripting
// via Golang.
func Example() {
// change below array to play with your own cmd args:
args := []string{"repo", "ls", "mcr.microsoft.com"}
cmd := cmd.NewRoot()
cmd.SetArgs(args)
fmt.Printf("Executing 'oras %s':", strings.Join(args, " "))
err := cmd.Execute()
if err != nil {
fmt.Errorf("Failed to execute : %w", err)
os.Exit(-1)
}
os.Exit(0)
}

0 comments on commit 8675b62

Please sign in to comment.