github.com/BarDweller/libpak@v0.0.0-20230630201634-8dd5cfc15ec9/cmd/create-package/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/BarDweller/libpak/carton" 27 ) 28 29 func main() { 30 p := carton.Package{} 31 32 flagSet := pflag.NewFlagSet("Create Package", pflag.ExitOnError) 33 flagSet.StringVar(&p.CacheLocation, "cache-location", "", "path to cache downloaded dependencies (default: $PWD/dependencies)") 34 flagSet.StringVar(&p.Destination, "destination", "", "path to the build package destination directory") 35 flagSet.BoolVar(&p.IncludeDependencies, "include-dependencies", false, "whether to include dependencies (default: false)") 36 flagSet.StringSliceVar(&p.DependencyFilters, "dependency-filter", []string{}, "one or more filters that are applied to exclude dependencies") 37 flagSet.BoolVar(&p.StrictDependencyFilters, "strict-filters", false, "require filter to match all data or just some data (default: false)") 38 flagSet.StringVar(&p.Source, "source", defaultSource(), "path to build package source directory (default: $PWD)") 39 flagSet.StringVar(&p.Version, "version", "", "version to substitute into buildpack.toml/extension.toml") 40 41 if err := flagSet.Parse(os.Args[1:]); err != nil { 42 log.Fatal(fmt.Errorf("unable to parse flags\n%w", err)) 43 } 44 45 if p.Destination == "" { 46 log.Fatal("destination must be set") 47 } 48 49 p.Create() 50 } 51 52 func defaultSource() string { 53 s, err := os.Getwd() 54 if err != nil { 55 log.Fatal(fmt.Errorf("unable to get working directory\n%w", err)) 56 } 57 58 return s 59 }