github.com/paketoio/libpak@v1.3.1/cmd/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/paketoio/libpak/carton" 25 "github.com/spf13/pflag" 26 ) 27 28 func main() { 29 p := carton.Package{} 30 31 flagSet := pflag.NewFlagSet("Build Package", pflag.ExitOnError) 32 flagSet.StringVar(&p.CacheLocation, "cache-location", "", "path to cache downloaded dependencies (default: $PWD/dependencies)") 33 flagSet.StringVar(&p.Destination, "destination", "", "path to the build package destination directory") 34 flagSet.BoolVar(&p.IncludeDependencies, "include-dependencies", true, "whether to include dependencies (default: true)") 35 flagSet.StringVar(&p.Source, "source", defaultSource(), "path to build package source directory (default: $PWD)") 36 flagSet.StringVar(&p.Version, "version", "", "version to substitute into buildpack.toml") 37 38 if err := flagSet.Parse(os.Args[1:]); err != nil { 39 log.Fatal(fmt.Errorf("unable to parse flags: %w", err)) 40 } 41 42 if p.Destination == "" { 43 log.Fatal("destination must be set") 44 } 45 46 p.Build() 47 } 48 49 func defaultSource() string { 50 s, err := os.Getwd() 51 if err != nil { 52 log.Fatal(fmt.Errorf("unable to get working directory: %w", err)) 53 } 54 55 return s 56 }