github.com/rrashidov/libpak@v0.0.0-20230911084305-75119185bb4d/cmd/update-buildpack-dependency/main.go (about)

     1  /*
     2   * Copyright 2018-2020 the original author or authors.
     3   *
     4   * Licensed under the Apache License, Version 2.0 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   *
     8   *      https://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   */
    16  
    17  package main
    18  
    19  import (
    20  	"fmt"
    21  	"log"
    22  	"os"
    23  
    24  	"github.com/spf13/pflag"
    25  
    26  	"github.com/paketo-buildpacks/libpak/carton"
    27  )
    28  
    29  func main() {
    30  	b := carton.BuildpackDependency{}
    31  
    32  	flagSet := pflag.NewFlagSet("Update Buildpack Dependency", pflag.ExitOnError)
    33  	flagSet.StringVar(&b.BuildpackPath, "buildpack-toml", "", "path to buildpack.toml")
    34  	flagSet.StringVar(&b.ID, "id", "", "the id of the dependency")
    35  	flagSet.StringVar(&b.SHA256, "sha256", "", "the new sha256 of the dependency")
    36  	flagSet.StringVar(&b.URI, "uri", "", "the new uri of the dependency")
    37  	flagSet.StringVar(&b.Version, "version", "", "the new version of the dependency")
    38  	flagSet.StringVar(&b.VersionPattern, "version-pattern", "", "the version pattern of the dependency")
    39  	flagSet.StringVar(&b.PURL, "purl", "", "the new purl version of the dependency, if not set defaults to version")
    40  	flagSet.StringVar(&b.PURLPattern, "purl-pattern", "", "the purl version pattern of the dependency, if not set defaults to version-pattern")
    41  	flagSet.StringVar(&b.CPE, "cpe", "", "the new version use in all CPEs, if not set defaults to version")
    42  	flagSet.StringVar(&b.CPEPattern, "cpe-pattern", "", "the cpe version pattern of the dependency, if not set defaults to version-pattern")
    43  
    44  	if err := flagSet.Parse(os.Args[1:]); err != nil {
    45  		log.Fatal(fmt.Errorf("unable to parse flags\n%w", err))
    46  	}
    47  
    48  	if b.BuildpackPath == "" {
    49  		log.Fatal("buildpack-toml must be set")
    50  	}
    51  
    52  	if b.ID == "" {
    53  		log.Fatal("id must be set")
    54  	}
    55  
    56  	if b.SHA256 == "" {
    57  		log.Fatal("sha256 must be set")
    58  	}
    59  
    60  	if b.URI == "" {
    61  		log.Fatal("uri must be set")
    62  	}
    63  
    64  	if b.Version == "" {
    65  		log.Fatal("version must be set")
    66  	}
    67  
    68  	if b.VersionPattern == "" {
    69  		log.Fatal("version-pattern must be set")
    70  	}
    71  
    72  	if b.PURL == "" {
    73  		b.PURL = b.Version
    74  	}
    75  
    76  	if b.PURLPattern == "" {
    77  		b.PURLPattern = b.VersionPattern
    78  	}
    79  
    80  	if b.CPE == "" {
    81  		b.CPE = b.Version
    82  	}
    83  
    84  	if b.CPEPattern == "" {
    85  		b.CPEPattern = b.VersionPattern
    86  	}
    87  
    88  	b.Update()
    89  }