Skip to content

Commit

Permalink
Merge pull request #156 from bobuhiro11/rm_tags
Browse files Browse the repository at this point in the history
flag: Remove go:build flag.
  • Loading branch information
bobuhiro11 authored Aug 26, 2023
2 parents 05ac886 + a7dbea1 commit f283b08
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 33 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ golangci: golangci-lint
test: bzImage vda.img
$(MAKE) generate
$(MAKE) golangci
go test -coverprofile c.out -tags test ./...
go test -coverprofile c.out ./...

.PHONY: clean
clean:
Expand Down
4 changes: 1 addition & 3 deletions flag/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import (
"strings"
)

type context struct{}

type cli struct {
type CLI struct {
Boot BootCMD `cmd:"" help:"Boots a new VM"`
Probe ProbeCMD `cmd:"" help:"Probes KVM capabilities and prints them"`
}
Expand Down
23 changes: 6 additions & 17 deletions flag/flag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"strconv"
"testing"

"github.com/alecthomas/kong"
"github.com/bobuhiro11/gokvm/flag"
)

Expand Down Expand Up @@ -39,18 +38,13 @@ func TestParsesize(t *testing.T) { // nolint:paralleltest
}
}

func TestCmdlineBootParsing(t *testing.T) {
t.Parallel()

func TestCmdlineBootParsing(t *testing.T) { // nolint:paralleltest
// Omit t.Parallel() because it modifies os.Args.
args := os.Args
defer func() {
os.Args = args
}()

var cli struct {
Boot flag.BootCMD `cmd:"" help:"Boots a new VM"`
}

os.Args = []string{
"gokvm",
"boot",
Expand All @@ -72,25 +66,20 @@ func TestCmdlineBootParsing(t *testing.T) {
"1",
}

kong.Parse(&cli, kong.Exit(func(_ int) { t.Fatal("parsing failed") }))
flag.Parse()
}

func TestCmdlineProbeParsing(t *testing.T) {
t.Parallel()

func TestCmdlineProbeParsing(t *testing.T) { // nolint:paralleltest
// Omit t.Parallel() because it modifies os.Args.
args := os.Args
defer func() {
os.Args = args
}()

var cli struct {
Probe flag.ProbeCMD `cmd:"" help:"Probes KVM capabilities and prints them"`
}

os.Args = []string{
"gokvm",
"probe",
}

kong.Parse(&cli, kong.Exit(func(_ int) { t.Fatal("parsing failed") }))
flag.Parse()
}
14 changes: 5 additions & 9 deletions flag/runs.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//go:build !test

package flag

import (
Expand All @@ -10,8 +8,8 @@ import (
"github.com/bobuhiro11/gokvm/vmm"
)

func Parse() error {
c := cli{}
func Parse() *kong.Context {
c := CLI{}

programName := "gokvm"
programDesc := "gokvm is a small Linux KVM Hypervisor which supports kernel boot"
Expand All @@ -25,20 +23,18 @@ func Parse() error {
Summary: true,
}))

err := ctx.Run(&context{})

return err
return ctx
}

func (d *ProbeCMD) Run(_ *context) error {
func (d *ProbeCMD) Run() error {
if err := probe.KVMCapabilities(); err != nil {
return err
}

return nil
}

func (s *BootCMD) Run(_ *context) error {
func (s *BootCMD) Run() error {
defparams := `console=ttyS0 earlyprintk=serial noapic noacpi notsc ` +
`debug apic=debug show_lapic=all mitigations=off lapic tsc_early_khz=2000 ` +
`dyndbg="file arch/x86/kernel/smpboot.c +plf ; file drivers/net/virtio_net.c +plf" pci=realloc=off ` +
Expand Down
4 changes: 1 addition & 3 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//go:build !test

package main

import (
Expand All @@ -9,7 +7,7 @@ import (
)

func main() {
if err := flag.Parse(); err != nil {
if err := flag.Parse().Run(); err != nil {
log.Fatal(err)
}
}

0 comments on commit f283b08

Please sign in to comment.