mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-05-06 22:18:28 +00:00
Refactored main.go
The main function - whuch runs aptly commands - has been taken out from main.go and included to the cmd package. This is useful for the aptly script run command, which should use that behaviour.
This commit is contained in:
30
main.go
30
main.go
@@ -1,38 +1,10 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/smira/aptly/cmd"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
fatal, ok := r.(*cmd.FatalError)
|
||||
if !ok {
|
||||
panic(r)
|
||||
}
|
||||
fmt.Println("ERROR:", fatal.Message)
|
||||
os.Exit(fatal.ReturnCode)
|
||||
}
|
||||
}()
|
||||
|
||||
command := cmd.RootCommand()
|
||||
|
||||
flags, args, err := command.ParseFlags(os.Args[1:])
|
||||
if err != nil {
|
||||
cmd.Fatal(err)
|
||||
}
|
||||
|
||||
err = cmd.InitContext(flags)
|
||||
if err != nil {
|
||||
cmd.Fatal(err)
|
||||
}
|
||||
defer cmd.ShutdownContext()
|
||||
|
||||
err = command.Dispatch(args)
|
||||
if err != nil {
|
||||
cmd.Fatal(err)
|
||||
}
|
||||
cmd.Run(os.Args[1:], true)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user