Skip to content

Commit d6b50e8

Browse files
committed
adds shell.Process to readme
problem: - not all last changes are reflected in the readme, eg shell.Process solution: - document it in Readme - document it in the CHANGES.dm - add it to example/main.go
1 parent 0d9452a commit d6b50e8

File tree

3 files changed

+41
-5
lines changed

3 files changed

+41
-5
lines changed

CHANGES.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
For now, dates (DD/MM/YYYY) are used until ishell gets stable enough to warrant tags.
22
Attempts will be made to ensure non breaking updates as much as possible.
3+
#### 28/05/2017
4+
* Added `shell.Process(os.Args[1:]...)` for non-interactive execution
5+
*
6+
37

48
#### 07/02/2016
59
Added multiline support to shell mode.

README.md

+27
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,32 @@ ishell.ProgressBar().Display(display)
213213
shell.SetHomeHistoryPath(".ishell_history")
214214
```
215215

216+
217+
### Non-interactive execution
218+
In some situations it is desired to exit the program directly after executing a single command.
219+
220+
```go
221+
// when started with "exit" as first argument, assume non-interactive execution
222+
if len(os.Args) > 1 && os.Args[1] == "exit" {
223+
shell.Process(os.Args[2:]...)
224+
} else {
225+
// start shell
226+
shell.Run()
227+
}
228+
```
229+
230+
```bash
231+
# Run normally - interactive mode:
232+
$ go run main.go
233+
... interactive shell
234+
235+
# Run non-interactivelly
236+
$ go run main.go exit greet Someusername
237+
> Sample Interactive Shell
238+
> Hello Someusername
239+
```
240+
241+
216242
### Example
217243
Available [here](https://github.com/abiosoft/ishell/blob/master/example/main.go).
218244
```sh
@@ -252,6 +278,7 @@ Library | Use
252278
[github.com/flynn-archive/go-shlex](http://github.com/flynn-archive/go-shlex) | splitting input into command and args.
253279
[github.com/chzyer/readline](github.com/chzyer/readline) | readline capabilities.
254280

281+
255282
## Donate
256283
```
257284
bitcoin:1GTHYEDiy2C7RzXn5nY4wVRaEN2GvLjwZN

example/main.go

+10-5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package main
33
import (
44
"errors"
55
"fmt"
6+
"os"
67
"strings"
78
"time"
89

@@ -169,9 +170,13 @@ This is another line of it.
169170
},
170171
})
171172

172-
// start shell
173-
shell.Run()
174-
175-
// teardown
176-
shell.Close()
173+
// when started with "exit" as first argument, assume non-interactive execution
174+
if len(os.Args) > 1 && os.Args[1] == "exit" {
175+
shell.Process(os.Args[2:]...)
176+
} else {
177+
// start shell
178+
shell.Run()
179+
// teardown
180+
shell.Close()
181+
}
177182
}

0 commit comments

Comments
 (0)