Files
aptly/cmd/run.go
T
Simon Aquino 3c7696ef7e 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.
2014-08-16 13:55:13 +00:00

43 lines
565 B
Go

package cmd
import (
"fmt"
"os"
)
func Run(cmd_args []string, exitOnPanic bool) {
defer func() {
if r := recover(); r != nil {
fatal, ok := r.(*FatalError)
if !ok {
panic(r)
}
fmt.Println("ERROR:", fatal.Message)
if exitOnPanic {
os.Exit(fatal.ReturnCode)
}
}
}()
command := RootCommand()
flags, args, err := command.ParseFlags(cmd_args)
if err != nil {
Fatal(err)
}
err = InitContext(flags)
if err != nil {
Fatal(err)
}
defer ShutdownContext()
err = command.Dispatch(args)
if err != nil {
Fatal(err)
}
}