Skip to content

Commit

Permalink
init test commit
Browse files Browse the repository at this point in the history
  • Loading branch information
kekeon committed Nov 25, 2018
1 parent 56d1ea5 commit b825573
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
22 changes: 22 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package main

import (
"jvm.com/parseCmd"
"fmt"
)

func main() {
cmd := parseCmd.ParseCmd()
fmt.Println(cmd.VersionFlag)
if cmd.VersionFlag {
fmt.Println("version 0.0.1")
} else if cmd.HelpFlag || cmd.Class == "" {
parseCmd.PrintUsage()
} else {
startJVM(cmd)
}
}

func startJVM(cmd *parseCmd.Cmd){
fmt.Printf("classpath: %s class:%s args:%v \n",cmd.CpOption, cmd.Class, cmd.Args)
}
39 changes: 39 additions & 0 deletions parseCmd/parseCmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package parseCmd

import (
"flag"
"fmt"
"os"
)

type Cmd struct {
HelpFlag bool
VersionFlag bool
CpOption string
Class string
Args []string
}

func ParseCmd() *Cmd {
cmd := &Cmd{}

flag.Usage = PrintUsage
flag.BoolVar(&cmd.HelpFlag, "help", false, "print help message")
flag.BoolVar(&cmd.HelpFlag, "?", false, "print help message")
flag.BoolVar(&cmd.HelpFlag, "version", false, "print version and exit")
flag.StringVar(&cmd.CpOption, "classpath", "", "classpath")
flag.StringVar(&cmd.CpOption, "cp", "", "classpath")
flag.Parse()

args := flag.Args()

if len(args) > 0 {
cmd.Class = args[0]
cmd.Args = args[1:]
}
return cmd
}

func PrintUsage() {
fmt.Printf("Usage: %s [-options] class [args...]\n", os.Args[0])
}

0 comments on commit b825573

Please sign in to comment.