mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-05-07 22:20:24 +00:00
Style fixes.
This commit is contained in:
+14
-1
@@ -18,7 +18,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Common context shared by all commands
|
// AptlyContext is a common context shared by all commands
|
||||||
type AptlyContext struct {
|
type AptlyContext struct {
|
||||||
flags *flag.FlagSet
|
flags *flag.FlagSet
|
||||||
configLoaded bool
|
configLoaded bool
|
||||||
@@ -39,15 +39,19 @@ type AptlyContext struct {
|
|||||||
|
|
||||||
var context *AptlyContext
|
var context *AptlyContext
|
||||||
|
|
||||||
|
// FatalError is type for panicking to abort execution with non-zero
|
||||||
|
// exit code and print meaningful explanation
|
||||||
type FatalError struct {
|
type FatalError struct {
|
||||||
ReturnCode int
|
ReturnCode int
|
||||||
Message string
|
Message string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fatal panics and aborts execution with exit code 1
|
||||||
func Fatal(err error) {
|
func Fatal(err error) {
|
||||||
panic(&FatalError{ReturnCode: 1, Message: err.Error()})
|
panic(&FatalError{ReturnCode: 1, Message: err.Error()})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Config loads and returns current configuration
|
||||||
func (context *AptlyContext) Config() *utils.ConfigStructure {
|
func (context *AptlyContext) Config() *utils.ConfigStructure {
|
||||||
if !context.configLoaded {
|
if !context.configLoaded {
|
||||||
var err error
|
var err error
|
||||||
@@ -87,6 +91,7 @@ func (context *AptlyContext) Config() *utils.ConfigStructure {
|
|||||||
return &utils.Config
|
return &utils.Config
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DependencyOptions calculates options related to dependecy handling
|
||||||
func (context *AptlyContext) DependencyOptions() int {
|
func (context *AptlyContext) DependencyOptions() int {
|
||||||
if context.dependencyOptions == -1 {
|
if context.dependencyOptions == -1 {
|
||||||
context.dependencyOptions = 0
|
context.dependencyOptions = 0
|
||||||
@@ -107,6 +112,7 @@ func (context *AptlyContext) DependencyOptions() int {
|
|||||||
return context.dependencyOptions
|
return context.dependencyOptions
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ArchitecturesList returns list of architectures fixed via command line or config
|
||||||
func (context *AptlyContext) ArchitecturesList() []string {
|
func (context *AptlyContext) ArchitecturesList() []string {
|
||||||
if context.architecturesList == nil {
|
if context.architecturesList == nil {
|
||||||
context.architecturesList = context.Config().Architectures
|
context.architecturesList = context.Config().Architectures
|
||||||
@@ -119,6 +125,7 @@ func (context *AptlyContext) ArchitecturesList() []string {
|
|||||||
return context.architecturesList
|
return context.architecturesList
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Progress creates or returns Progress object
|
||||||
func (context *AptlyContext) Progress() aptly.Progress {
|
func (context *AptlyContext) Progress() aptly.Progress {
|
||||||
if context.progress == nil {
|
if context.progress == nil {
|
||||||
context.progress = console.NewProgress()
|
context.progress = console.NewProgress()
|
||||||
@@ -128,6 +135,7 @@ func (context *AptlyContext) Progress() aptly.Progress {
|
|||||||
return context.progress
|
return context.progress
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Downloader returns instance of current downloader
|
||||||
func (context *AptlyContext) Downloader() aptly.Downloader {
|
func (context *AptlyContext) Downloader() aptly.Downloader {
|
||||||
if context.downloader == nil {
|
if context.downloader == nil {
|
||||||
context.downloader = http.NewDownloader(context.Config().DownloadConcurrency, context.Progress())
|
context.downloader = http.NewDownloader(context.Config().DownloadConcurrency, context.Progress())
|
||||||
@@ -136,10 +144,12 @@ func (context *AptlyContext) Downloader() aptly.Downloader {
|
|||||||
return context.downloader
|
return context.downloader
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DBPath builds path to database
|
||||||
func (context *AptlyContext) DBPath() string {
|
func (context *AptlyContext) DBPath() string {
|
||||||
return filepath.Join(context.Config().RootDir, "db")
|
return filepath.Join(context.Config().RootDir, "db")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Database opens and returns current instance of database
|
||||||
func (context *AptlyContext) Database() (database.Storage, error) {
|
func (context *AptlyContext) Database() (database.Storage, error) {
|
||||||
if context.database == nil {
|
if context.database == nil {
|
||||||
var err error
|
var err error
|
||||||
@@ -153,6 +163,7 @@ func (context *AptlyContext) Database() (database.Storage, error) {
|
|||||||
return context.database, nil
|
return context.database, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CollectionFactory builds factory producing all kinds of collections
|
||||||
func (context *AptlyContext) CollectionFactory() *deb.CollectionFactory {
|
func (context *AptlyContext) CollectionFactory() *deb.CollectionFactory {
|
||||||
if context.collectionFactory == nil {
|
if context.collectionFactory == nil {
|
||||||
db, err := context.Database()
|
db, err := context.Database()
|
||||||
@@ -165,6 +176,7 @@ func (context *AptlyContext) CollectionFactory() *deb.CollectionFactory {
|
|||||||
return context.collectionFactory
|
return context.collectionFactory
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PackagePool returns instance of PackagePool
|
||||||
func (context *AptlyContext) PackagePool() aptly.PackagePool {
|
func (context *AptlyContext) PackagePool() aptly.PackagePool {
|
||||||
if context.packagePool == nil {
|
if context.packagePool == nil {
|
||||||
context.packagePool = files.NewPackagePool(context.Config().RootDir)
|
context.packagePool = files.NewPackagePool(context.Config().RootDir)
|
||||||
@@ -173,6 +185,7 @@ func (context *AptlyContext) PackagePool() aptly.PackagePool {
|
|||||||
return context.packagePool
|
return context.packagePool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PublishedStorage returns instance of PublishedStorage
|
||||||
func (context *AptlyContext) PublishedStorage() aptly.PublishedStorage {
|
func (context *AptlyContext) PublishedStorage() aptly.PublishedStorage {
|
||||||
if context.publishedStorage == nil {
|
if context.publishedStorage == nil {
|
||||||
context.publishedStorage = files.NewPublishedStorage(context.Config().RootDir)
|
context.publishedStorage = files.NewPublishedStorage(context.Config().RootDir)
|
||||||
|
|||||||
Reference in New Issue
Block a user