github.com/wmuizelaar/kpt@v0.0.0-20221018115725-bd564717b2ed/internal/util/get/example_test.go (about) 1 // Copyright 2019 Google LLC 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package get_test 16 17 import ( 18 "path/filepath" 19 20 "github.com/GoogleContainerTools/kpt/internal/printer/fake" 21 "github.com/GoogleContainerTools/kpt/internal/util/get" 22 kptfilev1 "github.com/GoogleContainerTools/kpt/pkg/api/kptfile/v1" 23 ) 24 25 func ExampleCommand() { 26 err := get.Command{Git: &kptfilev1.Git{ 27 Repo: "https://github.com/example-org/example-repo", 28 Ref: "v1.0", 29 }}.Run(fake.CtxWithDefaultPrinter()) 30 if err != nil { 31 // handle error 32 } 33 } 34 35 func ExampleCommand_branch() { 36 err := get.Command{Git: &kptfilev1.Git{ 37 Repo: "https://github.com/example-org/example-repo", 38 Ref: "refs/heads/v1.0", 39 }}.Run(fake.CtxWithDefaultPrinter()) 40 if err != nil { 41 // handle error 42 } 43 } 44 45 func ExampleCommand_tag() { 46 err := get.Command{Git: &kptfilev1.Git{ 47 Repo: "https://github.com/example-org/example-repo", 48 Ref: "refs/tags/v1.0", 49 }}.Run(fake.CtxWithDefaultPrinter()) 50 if err != nil { 51 // handle error 52 } 53 } 54 55 func ExampleCommand_commit() { 56 err := get.Command{Git: &kptfilev1.Git{ 57 Repo: "https://github.com/example-org/example-repo", 58 Ref: "8186bef8e5c0621bf80fa8106bd595aae8b62884", 59 }}.Run(fake.CtxWithDefaultPrinter()) 60 if err != nil { 61 // handle error 62 } 63 } 64 65 func ExampleCommand_subdir() { 66 err := get.Command{ 67 Git: &kptfilev1.Git{ 68 Repo: "https://github.com/example-org/example-repo", 69 Ref: "v1.0", 70 Directory: filepath.Join("path", "to", "package"), 71 }, 72 }.Run(fake.CtxWithDefaultPrinter()) 73 if err != nil { 74 // handle error 75 } 76 } 77 78 func ExampleCommand_destination() { 79 err := get.Command{ 80 Git: &kptfilev1.Git{ 81 Repo: "https://github.com/example-org/example-repo", 82 Ref: "v1.0", 83 }, 84 Destination: "destination-dir"}.Run(fake.CtxWithDefaultPrinter()) 85 if err != nil { 86 // handle error 87 } 88 }