75 lines
2.0 KiB
Go
75 lines
2.0 KiB
Go
package cmd
|
|
|
|
import (
|
|
"errors"
|
|
"net"
|
|
"path/filepath"
|
|
"sylixos-uploader/common"
|
|
"sylixos-uploader/detector"
|
|
"sylixos-uploader/log"
|
|
"sylixos-uploader/parser"
|
|
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
var genYamlCmd = &cobra.Command{
|
|
Use: "gen-yaml",
|
|
Short: "generate upload yaml file from real evo project",
|
|
Long: `generate upload yaml file from real evo project`,
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
generateYamlFromRealEvo(ProjectPath, BasePrjPath, Device)
|
|
},
|
|
}
|
|
|
|
func generateYamlFromRealEvo(projectPath, basePath, device string) error {
|
|
u := new(parser.UploadSetting)
|
|
|
|
if projectPath == "" {
|
|
projectPath = "."
|
|
}
|
|
|
|
prj := detector.NewSylixOSPrj(projectPath)
|
|
|
|
if !prj.IsSylixOSPrj() {
|
|
log.DefaultLogger(log.LogLevelError, "%s is Not a SylixOS project!", projectPath)
|
|
return errors.New("not a SylixOS project")
|
|
}
|
|
|
|
if basePath != "" {
|
|
if !detector.NewSylixOSPrj(basePath).IsSylixOSPrj() {
|
|
log.DefaultLogger(log.LogLevelWarn, "Base is set but the path is not a SylixOS project!, ignore it.")
|
|
basePath = ""
|
|
}
|
|
}
|
|
|
|
u.GenerateFromRealEvo(projectPath, basePath)
|
|
deviceIP := net.ParseIP(device)
|
|
|
|
deviceXmlIP := net.ParseIP(u.RemoteSettings.IP)
|
|
|
|
if deviceIP != nil {
|
|
log.DefaultLogger(log.LogLevelInfo, "Override Device IP as %s", deviceIP.String())
|
|
u.RemoteSettings.IP = device
|
|
} else if deviceXmlIP != nil {
|
|
log.DefaultLogger(log.LogLevelInfo, "Use Device IP in XML as %s", deviceXmlIP.String())
|
|
} else {
|
|
log.DefaultLogger(log.LogLevelError, "No Valid Device IP in XML, please set Device IP by --device")
|
|
return errors.New("no valid device ip")
|
|
}
|
|
|
|
u.ClearYaml()
|
|
u.SaveYaml()
|
|
|
|
log.DefaultLogger(log.LogLevelInfo, "Generate Success: %s", filepath.Join(u.BaseSettings.ProjectPath, common.YamlFile))
|
|
return nil
|
|
}
|
|
|
|
func init() {
|
|
RootCmd.AddCommand(genYamlCmd)
|
|
|
|
// Adding flags with long names
|
|
genYamlCmd.Flags().StringVar(&ProjectPath, "path", "", "Project path")
|
|
genYamlCmd.Flags().StringVar(&BasePrjPath, "base", "", "Base project path")
|
|
genYamlCmd.Flags().StringVar(&Device, "device", "", "Device")
|
|
}
|