-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from nmi/add_flag
flag: add arguments for kernel & initrd path
- Loading branch information
Showing
3 changed files
with
57 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package flag | ||
|
||
import ( | ||
"flag" | ||
) | ||
|
||
func ParseArgs(args []string) (string, string, error) { | ||
kernel := flag.String("k", "./bzImage", "kernel image path") | ||
initrd := flag.String("i", "./initrd", "initrd path") | ||
|
||
flag.Parse() | ||
|
||
if err := flag.CommandLine.Parse(args[1:]); err != nil { | ||
return "", "", err | ||
} | ||
|
||
return *kernel, *initrd, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package flag_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/nmi/gokvm/flag" | ||
) | ||
|
||
func TestParseArg(t *testing.T) { | ||
t.Parallel() | ||
|
||
args := []string{ | ||
"gokvm", | ||
"-i", | ||
"initrd_path", | ||
"-k", | ||
"kernel_path", | ||
} | ||
|
||
kernel, initrd, err := flag.ParseArgs(args) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
if kernel != "kernel_path" { | ||
t.Fatal("invalid kernel image path") | ||
} | ||
|
||
if initrd != "initrd_path" { | ||
t.Fatal("invalid initrd path") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters