github.com/SamarSidharth/kpt@v0.0.0-20231122062228-c7d747ae3ace/internal/util/get/example_test.go (about)

     1  // Copyright 2019 The kpt Authors
     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  	"fmt"
    19  	"path/filepath"
    20  
    21  	"github.com/GoogleContainerTools/kpt/internal/util/get"
    22  	kptfilev1 "github.com/GoogleContainerTools/kpt/pkg/api/kptfile/v1"
    23  	"github.com/GoogleContainerTools/kpt/pkg/printer/fake"
    24  )
    25  
    26  func ExampleCommand() {
    27  	err := get.Command{Git: &kptfilev1.Git{
    28  		Repo: "https://github.com/example-org/example-repo",
    29  		Ref:  "v1.0",
    30  	}}.Run(fake.CtxWithDefaultPrinter())
    31  	if err != nil {
    32  		fmt.Print(err.Error())
    33  	}
    34  }
    35  
    36  func ExampleCommand_branch() {
    37  	err := get.Command{Git: &kptfilev1.Git{
    38  		Repo: "https://github.com/example-org/example-repo",
    39  		Ref:  "refs/heads/v1.0",
    40  	}}.Run(fake.CtxWithDefaultPrinter())
    41  	if err != nil {
    42  		fmt.Print(err.Error())
    43  	}
    44  }
    45  
    46  func ExampleCommand_tag() {
    47  	err := get.Command{Git: &kptfilev1.Git{
    48  		Repo: "https://github.com/example-org/example-repo",
    49  		Ref:  "refs/tags/v1.0",
    50  	}}.Run(fake.CtxWithDefaultPrinter())
    51  	if err != nil {
    52  		fmt.Print(err.Error())
    53  	}
    54  }
    55  
    56  func ExampleCommand_commit() {
    57  	err := get.Command{Git: &kptfilev1.Git{
    58  		Repo: "https://github.com/example-org/example-repo",
    59  		Ref:  "8186bef8e5c0621bf80fa8106bd595aae8b62884",
    60  	}}.Run(fake.CtxWithDefaultPrinter())
    61  	if err != nil {
    62  		fmt.Print(err.Error())
    63  	}
    64  }
    65  
    66  func ExampleCommand_subdir() {
    67  	err := get.Command{
    68  		Git: &kptfilev1.Git{
    69  			Repo:      "https://github.com/example-org/example-repo",
    70  			Ref:       "v1.0",
    71  			Directory: filepath.Join("path", "to", "package"),
    72  		},
    73  	}.Run(fake.CtxWithDefaultPrinter())
    74  	if err != nil {
    75  		fmt.Print(err.Error())
    76  	}
    77  }
    78  
    79  func ExampleCommand_destination() {
    80  	err := get.Command{
    81  		Git: &kptfilev1.Git{
    82  			Repo: "https://github.com/example-org/example-repo",
    83  			Ref:  "v1.0",
    84  		},
    85  		Destination: "destination-dir"}.Run(fake.CtxWithDefaultPrinter())
    86  	if err != nil {
    87  		fmt.Print(err.Error())
    88  	}
    89  }