Przeglądaj źródła

add a `help` command, document `run` in the readme

Lucas Stadler 11 lat temu
rodzic
commit
469f6af424
2 zmienionych plików z 34 dodań i 0 usunięć
  1. 17 0
      go/linguaevalia/README.md
  2. 17 0
      go/linguaevalia/linguaevalia.go

+ 17 - 0
go/linguaevalia/README.md

@ -40,6 +40,23 @@ If there isn't, you can either write a wrapper to do that (similar to the
40 40
[one for rust](./bin/run-rust)) or you can implement the `Language`
41 41
interface.
42 42
43
## Additional commands
44
45
`linguaevalia` can also be used to run programs directly, instead of using the
46
server:
47
48
```
49
$ linguaevalia run hello-world.rb
50
Hello, World!
51
# or alternatively:
52
$ cat hello-world.rb | linguaevalia run -l ruby
53
Hello, World!
54
```
55
56
When passing code to the `run` command via stdin, you *must* set the language
57
to be used using the `-l` flag as well. If a file name is passed, the type is
58
inferred from the extension, but you can override it with `-l` if you want.
59
43 60
## Development setup
44 61
45 62
```

+ 17 - 0
go/linguaevalia/linguaevalia.go

@ -221,6 +221,21 @@ func runOnce(args []string) {
221 221
	}
222 222
}
223 223
224
func runHelp() {
225
	fmt.Printf(`Usage: %s [cmd] [options]
226
227
Availlable commands:
228
229
server		- Starts a web server. (Default.)
230
run		- Runs code from a file or from stdin.
231
		  (If running from stdin, you must pass the language
232
		   using the -l flag.)
233
help		- Display this help message.
234
235
`,
236
		os.Args[0])
237
}
238
224 239
func parseCommand() (string, []string) {
225 240
	if len(os.Args) == 1 {
226 241
		return "server", []string{}
@ -240,6 +255,8 @@ func main() {
240 255
		runServer()
241 256
	case "run":
242 257
		runOnce(flag.Args())
258
	case "help":
259
		runHelp()
243 260
	default:
244 261
		fmt.Println("Error: Unknown command:", cmd)
245 262
		os.Exit(1)