mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-06-11 06:24:04 +00:00
Fixes for refactoring to cmd.
This commit is contained in:
@@ -36,7 +36,6 @@ func RootCommand() *commander.Command {
|
|||||||
UsageLine: os.Args[0],
|
UsageLine: os.Args[0],
|
||||||
Short: "Debian repository management tool",
|
Short: "Debian repository management tool",
|
||||||
Long: `
|
Long: `
|
||||||
}
|
|
||||||
aptly is a tool to create partial and full mirrors of remote
|
aptly is a tool to create partial and full mirrors of remote
|
||||||
repositories, filter them, merge, upgrade individual packages,
|
repositories, filter them, merge, upgrade individual packages,
|
||||||
take snapshots and publish them back as Debian repositories.`,
|
take snapshots and publish them back as Debian repositories.`,
|
||||||
|
|||||||
+8
-3
@@ -25,6 +25,7 @@ var context struct {
|
|||||||
architecturesList []string
|
architecturesList []string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// InitContext initializes context with default settings
|
||||||
func InitContext(cmd *commander.Command) error {
|
func InitContext(cmd *commander.Command) error {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
@@ -50,19 +51,23 @@ func InitContext(cmd *commander.Command) error {
|
|||||||
|
|
||||||
context.progress = console.NewProgress()
|
context.progress = console.NewProgress()
|
||||||
context.progress.Start()
|
context.progress.Start()
|
||||||
defer context.progress.Shutdown()
|
|
||||||
|
|
||||||
context.downloader = http.NewDownloader(utils.Config.DownloadConcurrency, context.progress)
|
context.downloader = http.NewDownloader(utils.Config.DownloadConcurrency, context.progress)
|
||||||
defer context.downloader.Shutdown()
|
|
||||||
|
|
||||||
context.database, err = database.OpenDB(filepath.Join(utils.Config.RootDir, "db"))
|
context.database, err = database.OpenDB(filepath.Join(utils.Config.RootDir, "db"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("can't open database: %s", err)
|
return fmt.Errorf("can't open database: %s", err)
|
||||||
}
|
}
|
||||||
defer context.database.Close()
|
|
||||||
|
|
||||||
context.packagePool = files.NewPackagePool(utils.Config.RootDir)
|
context.packagePool = files.NewPackagePool(utils.Config.RootDir)
|
||||||
context.publishedStorage = files.NewPublishedStorage(utils.Config.RootDir)
|
context.publishedStorage = files.NewPublishedStorage(utils.Config.RootDir)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ShutdownContext shuts context down
|
||||||
|
func ShutdownContext() {
|
||||||
|
context.database.Close()
|
||||||
|
context.downloader.Shutdown()
|
||||||
|
context.progress.Shutdown()
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,79 +3,26 @@ package main
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/gonuts/commander"
|
"github.com/gonuts/commander"
|
||||||
"github.com/gonuts/flag"
|
"github.com/smira/aptly/cmd"
|
||||||
"github.com/smira/aptly/aptly"
|
|
||||||
"github.com/smira/aptly/console"
|
|
||||||
"github.com/smira/aptly/database"
|
|
||||||
"github.com/smira/aptly/debian"
|
|
||||||
"github.com/smira/aptly/files"
|
|
||||||
"github.com/smira/aptly/http"
|
|
||||||
"github.com/smira/aptly/utils"
|
"github.com/smira/aptly/utils"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// aptly version
|
|
||||||
const Version = "0.4~dev"
|
|
||||||
|
|
||||||
var cmd *commander.Command
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
cmd = &commander.Command{
|
|
||||||
UsageLine: os.Args[0],
|
|
||||||
Short: "Debian repository management tool",
|
|
||||||
Long: `
|
|
||||||
aptly is a tool to create partial and full mirrors of remote
|
|
||||||
repositories, filter them, merge, upgrade individual packages,
|
|
||||||
take snapshots and publish them back as Debian repositories.`,
|
|
||||||
Flag: *flag.NewFlagSet("aptly", flag.ExitOnError),
|
|
||||||
Subcommands: []*commander.Command{
|
|
||||||
makeCmdDb(),
|
|
||||||
makeCmdGraph(),
|
|
||||||
makeCmdMirror(),
|
|
||||||
makeCmdServe(),
|
|
||||||
makeCmdSnapshot(),
|
|
||||||
makeCmdPublish(),
|
|
||||||
makeCmdVersion(),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
cmd.Flag.Bool("dep-follow-suggests", false, "when processing dependencies, follow Suggests")
|
|
||||||
cmd.Flag.Bool("dep-follow-source", false, "when processing dependencies, follow from binary to Source packages")
|
|
||||||
cmd.Flag.Bool("dep-follow-recommends", false, "when processing dependencies, follow Recommends")
|
|
||||||
cmd.Flag.Bool("dep-follow-all-variants", false, "when processing dependencies, follow a & b if depdency is 'a|b'")
|
|
||||||
cmd.Flag.String("architectures", "", "list of architectures to consider during (comma-separated), default to all available")
|
|
||||||
cmd.Flag.String("config", "", "location of configuration file (default locations are /etc/aptly.conf, ~/.aptly.conf)")
|
|
||||||
}
|
|
||||||
|
|
||||||
var context struct {
|
|
||||||
progress aptly.Progress
|
|
||||||
downloader aptly.Downloader
|
|
||||||
database database.Storage
|
|
||||||
packagePool aptly.PackagePool
|
|
||||||
publishedStorage aptly.PublishedStorage
|
|
||||||
dependencyOptions int
|
|
||||||
architecturesList []string
|
|
||||||
}
|
|
||||||
|
|
||||||
func fatal(err error) {
|
func fatal(err error) {
|
||||||
fmt.Printf("ERROR: %s\n", err)
|
fmt.Printf("ERROR: %s\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func loadConfig(command *commander.Command) error {
|
||||||
err := cmd.Flag.Parse(os.Args[1:])
|
var err error
|
||||||
if err != nil {
|
|
||||||
fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
configLocation := cmd.Flag.Lookup("config").Value.String()
|
configLocation := command.Flag.Lookup("config").Value.String()
|
||||||
if configLocation != "" {
|
if configLocation != "" {
|
||||||
err = utils.LoadConfig(configLocation, &utils.Config)
|
err = utils.LoadConfig(configLocation, &utils.Config)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fatal(err)
|
return err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
configLocations := []string{
|
configLocations := []string{
|
||||||
@@ -99,43 +46,29 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
context.dependencyOptions = 0
|
return nil
|
||||||
if utils.Config.DepFollowSuggests || cmd.Flag.Lookup("dep-follow-suggests").Value.Get().(bool) {
|
}
|
||||||
context.dependencyOptions |= debian.DepFollowSuggests
|
|
||||||
}
|
|
||||||
if utils.Config.DepFollowRecommends || cmd.Flag.Lookup("dep-follow-recommends").Value.Get().(bool) {
|
|
||||||
context.dependencyOptions |= debian.DepFollowRecommends
|
|
||||||
}
|
|
||||||
if utils.Config.DepFollowAllVariants || cmd.Flag.Lookup("dep-follow-all-variants").Value.Get().(bool) {
|
|
||||||
context.dependencyOptions |= debian.DepFollowAllVariants
|
|
||||||
}
|
|
||||||
if utils.Config.DepFollowSource || cmd.Flag.Lookup("dep-follow-source").Value.Get().(bool) {
|
|
||||||
context.dependencyOptions |= debian.DepFollowSource
|
|
||||||
}
|
|
||||||
|
|
||||||
context.architecturesList = utils.Config.Architectures
|
func main() {
|
||||||
optionArchitectures := cmd.Flag.Lookup("architectures").Value.String()
|
command := cmd.RootCommand()
|
||||||
if optionArchitectures != "" {
|
|
||||||
context.architecturesList = strings.Split(optionArchitectures, ",")
|
|
||||||
}
|
|
||||||
|
|
||||||
context.progress = console.NewProgress()
|
err := command.Flag.Parse(os.Args[1:])
|
||||||
context.progress.Start()
|
|
||||||
defer context.progress.Shutdown()
|
|
||||||
|
|
||||||
context.downloader = http.NewDownloader(utils.Config.DownloadConcurrency, context.progress)
|
|
||||||
defer context.downloader.Shutdown()
|
|
||||||
|
|
||||||
context.database, err = database.OpenDB(filepath.Join(utils.Config.RootDir, "db"))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fatal(fmt.Errorf("can't open database: %s", err))
|
fatal(err)
|
||||||
}
|
}
|
||||||
defer context.database.Close()
|
|
||||||
|
|
||||||
context.packagePool = files.NewPackagePool(utils.Config.RootDir)
|
err = loadConfig(command)
|
||||||
context.publishedStorage = files.NewPublishedStorage(utils.Config.RootDir)
|
if err != nil {
|
||||||
|
fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
err = cmd.Dispatch(cmd.Flag.Args())
|
err = cmd.InitContext(command)
|
||||||
|
if err != nil {
|
||||||
|
fatal(err)
|
||||||
|
}
|
||||||
|
defer cmd.ShutdownContext()
|
||||||
|
|
||||||
|
err = command.Dispatch(command.Flag.Args())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fatal(err)
|
fatal(err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user