2020-03-16 07:33:51 +00:00
|
|
|
// Copyright © 2020 Ettore Di Giacinto <mudler@gentoo.org>
|
|
|
|
// Daniele Rondina <geaaru@sabayonlinux.org>
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation; either version 2 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License along
|
|
|
|
// with this program; if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
package cmd_tree
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2021-10-20 22:13:02 +00:00
|
|
|
"github.com/mudler/luet/cmd/util"
|
2020-05-20 06:31:55 +00:00
|
|
|
spectooling "github.com/mudler/luet/pkg/spectooling"
|
2020-03-16 07:33:51 +00:00
|
|
|
tree "github.com/mudler/luet/pkg/tree"
|
2020-08-30 06:54:38 +00:00
|
|
|
version "github.com/mudler/luet/pkg/versioner"
|
2020-03-16 07:33:51 +00:00
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
func NewTreeBumpCommand() *cobra.Command {
|
|
|
|
|
|
|
|
var ans = &cobra.Command{
|
|
|
|
Use: "bump [OPTIONS]",
|
|
|
|
Short: "Bump a new package build version.",
|
|
|
|
Args: cobra.OnlyValidArgs,
|
|
|
|
PreRun: func(cmd *cobra.Command, args []string) {
|
|
|
|
df, _ := cmd.Flags().GetString("definition-file")
|
|
|
|
if df == "" {
|
2021-10-20 22:13:02 +00:00
|
|
|
util.DefaultContext.Fatal("Mandatory definition.yaml path missing.")
|
2020-03-16 07:33:51 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
|
|
spec, _ := cmd.Flags().GetString("definition-file")
|
2020-04-04 11:42:25 +00:00
|
|
|
toStdout, _ := cmd.Flags().GetBool("to-stdout")
|
2020-08-30 06:54:38 +00:00
|
|
|
pkgVersion, _ := cmd.Flags().GetString("pkg-version")
|
2020-03-16 07:33:51 +00:00
|
|
|
pack, err := tree.ReadDefinitionFile(spec)
|
|
|
|
if err != nil {
|
2021-10-20 22:13:02 +00:00
|
|
|
util.DefaultContext.Fatal(err.Error())
|
2020-03-16 07:33:51 +00:00
|
|
|
}
|
|
|
|
|
2020-08-30 06:54:38 +00:00
|
|
|
if pkgVersion != "" {
|
|
|
|
validator := &version.WrappedVersioner{}
|
|
|
|
err := validator.Validate(pkgVersion)
|
|
|
|
if err != nil {
|
2021-10-20 22:13:02 +00:00
|
|
|
util.DefaultContext.Fatal("Invalid version string: " + err.Error())
|
2020-08-30 06:54:38 +00:00
|
|
|
}
|
|
|
|
pack.SetVersion(pkgVersion)
|
|
|
|
} else {
|
|
|
|
// Retrieve version build section with Gentoo parser
|
|
|
|
err = pack.BumpBuildVersion()
|
|
|
|
if err != nil {
|
2021-10-20 22:13:02 +00:00
|
|
|
util.DefaultContext.Fatal("Error on increment build version: " + err.Error())
|
2020-08-30 06:54:38 +00:00
|
|
|
}
|
2020-03-16 07:33:51 +00:00
|
|
|
}
|
2020-04-04 11:42:25 +00:00
|
|
|
if toStdout {
|
2020-05-20 06:31:55 +00:00
|
|
|
data, err := spectooling.NewDefaultPackageSanitized(&pack).Yaml()
|
2020-04-04 11:42:25 +00:00
|
|
|
if err != nil {
|
2021-10-20 22:13:02 +00:00
|
|
|
util.DefaultContext.Fatal("Error on yaml conversion: " + err.Error())
|
2020-04-04 11:42:25 +00:00
|
|
|
}
|
|
|
|
fmt.Println(string(data))
|
|
|
|
} else {
|
2020-03-16 07:33:51 +00:00
|
|
|
|
2020-04-04 11:42:25 +00:00
|
|
|
err = tree.WriteDefinitionFile(&pack, spec)
|
|
|
|
if err != nil {
|
2021-10-20 22:13:02 +00:00
|
|
|
util.DefaultContext.Fatal("Error on write definition file: " + err.Error())
|
2020-04-04 11:42:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Printf("Bumped package %s/%s-%s.\n", pack.Category, pack.Name, pack.Version)
|
|
|
|
}
|
2020-03-16 07:33:51 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2020-08-30 06:54:38 +00:00
|
|
|
ans.Flags().StringP("pkg-version", "p", "", "Set a specific package version")
|
2020-03-16 07:33:51 +00:00
|
|
|
ans.Flags().StringP("definition-file", "f", "", "Path of the definition to bump.")
|
2020-04-04 11:42:25 +00:00
|
|
|
ans.Flags().BoolP("to-stdout", "o", false, "Bump package to output.")
|
2020-03-16 07:33:51 +00:00
|
|
|
|
|
|
|
return ans
|
|
|
|
}
|