func main() { ctx := *core.NewContext() // Register new sub-commands here registry = NewCommandRegistry() registry.RegisterSubCommand("ping", cmd.NewPingCommand(ctx)) registry.RegisterSubCommand("init", cmd.NewInitCommand(ctx)) registry.RegisterSubCommand("search", cmd.NewSearchCommand(ctx)) registry.RegisterSubCommand("list", cmd.NewListCommand(ctx)) registry.RegisterSubCommand("info", cmd.NewInfoCommand(ctx)) registry.RegisterSubCommand("install", cmd.NewInstallCommand(ctx)) registry.RegisterSubCommand("uninstall", cmd.NewUninstallCommand(ctx)) registry.RegisterSubCommand("publish", cmd.NewPublishCommand(ctx)) registry.RegisterSubCommand("help", cmd.NewHelpCommand(ctx)) registry.RegisterSubCommand("check", cmd.NewCheckCommand(ctx)) registry.RegisterSubCommand("sign", cmd.NewSignCommand(ctx)) registry.RegisterSubCommand("verify", cmd.NewVerifyCommand(ctx)) //registry.RegisterSubCommand("deprecate", cmd.NewDeprecateCommand(ctx)) //registry.RegisterSubCommand("prune", cmd.NewPruneCommand(ctx)) if len(os.Args) < 2 { Usage() return } subCmd := os.Args[1] if !registry.Exists(subCmd) { Usage() return } command := registry.Get(subCmd) fs := flag.NewFlagSet(os.Args[0], flag.ExitOnError) fs.Usage = func() { Usage() fs.PrintDefaults() } command.RegisterFlags(fs) fs.Parse(os.Args[2:]) command.Run() }
func main() { binDir, err := filepath.Abs(filepath.Dir(os.Args[0])) if err != nil { log.Fatalf("Error getting bin dir: %v\n", err) } var outputDir string if len(os.Args) < 2 { outputDir, err = filepath.Abs(repositoryDir) } else { outputDir, err = filepath.Abs(os.Args[1]) } if err != nil { log.Fatalf("Error getting output dir: %v\n", err) } staging := newDir(filepath.Join(outputDir, stagingDir)) log.Printf("Generated repository at %s\n", outputDir) buffer := bytes.NewBufferString(staging) reset := buffer.Len() pkg := &packageInfo{ Root: packageName, Version: core.Version, ReleaseDate: time.Now().Format("2006-01-02"), } rootMetaDir := newDir(filepath.Join(staging, packageName, "meta")) newDir(filepath.Join(staging, packageName, "data")) if err = writeTemplate(filepath.Join(rootMetaDir, "package.xml"), rootPackageXml, pkg); err != nil { log.Fatalf("Could not generate package.xml for root %s", err.Error()) } req := &msg.LicenseRequest{ Package: &msg.Package{ Name: "qpm", Description: "A package manager for Qt", License: qpmLicense, Version: &msg.Package_Version{ Label: core.Version, }, Author: &msg.Package_Author{ Name: "Cutehacks AS", }, }, } ctx := core.NewContext() license, err := ctx.Client.GetLicense(context.Background(), req) if err != nil { log.Fatalf("Could not fetch license info:", err.Error()) } licenseTxt := license.Body + licenseAddendum if err = writeText(filepath.Join(rootMetaDir, "license.txt"), licenseTxt); err != nil { log.Fatalf("Could not generate license.txt for root %s", err.Error()) } for platform, binary := range platforms { srcDir := filepath.Join(binDir, platform) if _, err := os.Stat(srcDir); err != nil { log.Printf("Platform %s does not exist", platform) continue } // Create meta dir buffer.Truncate(reset) buffer.WriteString("/" + packageName + ".") buffer.WriteString(platform) buffer.WriteString("/meta/") metaDir := buffer.String() newDir(metaDir) // Create data dir buffer.Truncate(reset) buffer.WriteString("/" + packageName + ".") buffer.WriteString(platform) buffer.WriteString("/data/qpm/") dataDir := buffer.String() newDir(dataDir) if err := copyBinary(filepath.Join(srcDir, binary), filepath.Join(dataDir, binary)); err != nil { log.Fatalf("Cannot copy binary to %s: %s", dataDir, err.Error()) } pkg.Platform = platform if err := writeTemplate(filepath.Join(metaDir, "package.xml"), platformPackageXml, pkg); err != nil { log.Fatalf("Could not generate package.xml for %s: %s", platform, err.Error()) } } }