mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-05-06 22:18:28 +00:00
3c7696ef7e
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.
43 lines
565 B
Go
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)
|
|
}
|
|
|
|
}
|