mirror of
https://github.com/goreleaser/nfpm
synced 2024-06-10 06:16:12 +02:00
chore: improved cli
This commit is contained in:
parent
4b73ac9428
commit
00335c9c83
|
@ -13,28 +13,58 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
app = kingpin.New("pkg", "packages apps")
|
||||
config = app.Flag("config", "config file").ExistingFile()
|
||||
format = app.Flag("format", "format to package").Default("deb").String()
|
||||
target = app.Flag("target", "where to save the package").Required().String()
|
||||
app = kingpin.New("nfpm", "not-fpm packages apps in some formats")
|
||||
config = app.Flag("config", "config file").Default("nfpm.yaml").String()
|
||||
|
||||
pkgCmd = app.Command("pkg", "package based on the config file")
|
||||
format = pkgCmd.Flag("format", "format to package").Default("deb").String()
|
||||
target = pkgCmd.Flag("target", "where to save the package").Required().String()
|
||||
|
||||
initCmd = app.Command("init", "create an empty config file")
|
||||
)
|
||||
|
||||
func main() {
|
||||
kingpin.MustParse(app.Parse(os.Args[1:]))
|
||||
switch kingpin.MustParse(app.Parse(os.Args[1:])) {
|
||||
case initCmd.FullCommand():
|
||||
if err := initFile(*config); err != nil {
|
||||
kingpin.Fatalf(err.Error())
|
||||
}
|
||||
fmt.Printf("created empty config file at %s, edit at will\n", *config)
|
||||
case pkgCmd.FullCommand():
|
||||
if err := doPackage(*config, *format, *target); err != nil {
|
||||
kingpin.Fatalf(err.Error())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bts, err := ioutil.ReadFile(*config)
|
||||
kingpin.FatalIfError(err, "")
|
||||
|
||||
var info nfpm.Info
|
||||
kingpin.FatalIfError(yaml.Unmarshal(bts, &info), "%v")
|
||||
|
||||
pkg, err := nfpm.Get(*format)
|
||||
func initFile(config string) error {
|
||||
yml, err := yaml.Marshal(nfpm.Info{})
|
||||
if err != nil {
|
||||
kingpin.Fatalf(err.Error())
|
||||
return err
|
||||
}
|
||||
return ioutil.WriteFile(config, yml, 0666)
|
||||
}
|
||||
|
||||
func doPackage(config, format, target string) error {
|
||||
bts, err := ioutil.ReadFile(config)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
f, err := os.Create(*target)
|
||||
kingpin.FatalIfError(err, "")
|
||||
kingpin.FatalIfError(pkg.Package(info, f), "")
|
||||
fmt.Println("done:", *target)
|
||||
var info nfpm.Info
|
||||
err = yaml.Unmarshal(bts, &info)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
pkg, err := nfpm.Get(format)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
f, err := os.Create(target)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return pkg.Package(info, f)
|
||||
}
|
||||
|
|
36
nfpm.go
36
nfpm.go
|
@ -36,24 +36,24 @@ type Packager interface {
|
|||
|
||||
// Info contains information about the package
|
||||
type Info struct {
|
||||
Name string `yaml:"name,omitempty"`
|
||||
Arch string `yaml:"arch,omitempty"`
|
||||
Platform string `yaml:"platform,omitempty"`
|
||||
Version string `yaml:"version,omitempty"`
|
||||
Section string `yaml:"section,omitempty"`
|
||||
Priority string `yaml:"priority,omitempty"`
|
||||
Replaces []string `yaml:"replaces,omitempty"`
|
||||
Provides []string `yaml:"provides,omitempty"`
|
||||
Depends []string `yaml:"depends,omitempty"`
|
||||
Conflicts []string `yaml:"conflicts,omitempty"`
|
||||
Maintainer string `yaml:"maintainer,omitempty"`
|
||||
Description string `yaml:"description,omitempty"`
|
||||
Vendor string `yaml:"vendor,omitempty"`
|
||||
Homepage string `yaml:"homepage,omitempty"`
|
||||
License string `yaml:"license,omitempty"`
|
||||
Bindir string `yaml:"bindir,omitempty"`
|
||||
Files map[string]string `yaml:"files,omitempty"`
|
||||
ConfigFiles map[string]string `yaml:"config_files,omitempty"`
|
||||
Name string `yaml:"name"`
|
||||
Arch string `yaml:"arch"`
|
||||
Platform string `yaml:"platform"`
|
||||
Version string `yaml:"version"`
|
||||
Section string `yaml:"section"`
|
||||
Priority string `yaml:"priority"`
|
||||
Replaces []string `yaml:"replaces"`
|
||||
Provides []string `yaml:"provides"`
|
||||
Depends []string `yaml:"depends"`
|
||||
Conflicts []string `yaml:"conflicts"`
|
||||
Maintainer string `yaml:"maintainer"`
|
||||
Description string `yaml:"description"`
|
||||
Vendor string `yaml:"vendor"`
|
||||
Homepage string `yaml:"homepage"`
|
||||
License string `yaml:"license"`
|
||||
Bindir string `yaml:"bindir"`
|
||||
Files map[string]string `yaml:"files"`
|
||||
ConfigFiles map[string]string `yaml:"config_files"`
|
||||
}
|
||||
|
||||
// WithDefaults set some sane defaults into the given Info
|
||||
|
|
Loading…
Reference in New Issue