1
0
out-of-tree/main.go

90 lines
2.2 KiB
Go
Raw Normal View History

2023-01-31 07:13:33 +00:00
// Copyright 2023 Mikhail Klementev. All rights reserved.
2018-10-08 20:51:32 +00:00
// Use of this source code is governed by a AGPLv3 license
// (or later) that can be found in the LICENSE file.
package main
import (
2018-12-10 02:51:15 +00:00
"fmt"
"math/rand"
2023-03-18 21:30:07 +00:00
"os"
"time"
2023-03-18 21:30:07 +00:00
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
2023-01-31 07:13:33 +00:00
"github.com/alecthomas/kong"
2018-11-17 20:18:50 +00:00
2019-02-02 21:24:29 +00:00
"code.dumpstack.io/tools/out-of-tree/config"
)
2023-01-31 07:13:33 +00:00
type Globals struct {
Config config.OutOfTree `help:"path to out-of-tree configuration" default:"~/.out-of-tree/out-of-tree.toml"`
2023-01-31 07:13:33 +00:00
WorkDir string `help:"path to work directory" default:"./" type:"path"`
}
2023-01-31 07:13:33 +00:00
type CLI struct {
Globals
2023-01-31 07:13:33 +00:00
Pew PewCmd `cmd:"" help:"build, run, and test module/exploit"`
Kernel KernelCmd `cmd:"" help:"manipulate kernels"`
Debug DebugCmd `cmd:"" help:"debug environment"`
Log LogCmd `cmd:"" help:"query logs"`
Pack PackCmd `cmd:"" help:"exploit pack test"`
Gen GenCmd `cmd:"" help:"generate .out-of-tree.toml skeleton"`
2023-02-15 10:17:57 +00:00
Image ImageCmd `cmd:"" help:"manage images"`
2023-01-31 07:13:33 +00:00
Version VersionFlag `name:"version" help:"print version information and quit"`
2023-03-18 21:53:53 +00:00
2023-03-18 22:34:44 +00:00
LogLevel LogLevelFlag `enum:"debug,info,warn,error" default:"debug"`
2023-03-18 21:53:53 +00:00
}
type LogLevelFlag string
func (loglevel LogLevelFlag) AfterApply() error {
switch loglevel {
case "debug":
zerolog.SetGlobalLevel(zerolog.DebugLevel)
case "info":
zerolog.SetGlobalLevel(zerolog.InfoLevel)
case "warn":
zerolog.SetGlobalLevel(zerolog.WarnLevel)
case "error":
zerolog.SetGlobalLevel(zerolog.ErrorLevel)
}
return nil
}
2023-01-31 07:13:33 +00:00
type VersionFlag string
2018-12-10 02:51:15 +00:00
2023-01-31 07:13:33 +00:00
func (v VersionFlag) Decode(ctx *kong.DecodeContext) error { return nil }
func (v VersionFlag) IsBool() bool { return true }
func (v VersionFlag) BeforeApply(app *kong.Kong, vars kong.Vars) error {
fmt.Println(vars["version"])
app.Exit(0)
return nil
}
func main() {
2023-03-18 21:30:07 +00:00
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr})
2019-08-16 00:04:57 +00:00
rand.Seed(time.Now().UnixNano())
2023-01-31 07:13:33 +00:00
cli := CLI{}
ctx := kong.Parse(&cli,
kong.Name("out-of-tree"),
kong.Description("kernel {module, exploit} development tool"),
kong.UsageOnError(),
kong.ConfigureHelp(kong.HelpOptions{
Compact: true,
}),
kong.Vars{
"version": "1.4.0",
},
2018-10-27 08:14:10 +00:00
)
2023-01-31 07:13:33 +00:00
err := ctx.Run(&cli.Globals)
ctx.FatalIfErrorf(err)
}