File tree 3 files changed +41
-5
lines changed
3 files changed +41
-5
lines changed Original file line number Diff line number Diff line change 1
1
For now, dates (DD/MM/YYYY) are used until ishell gets stable enough to warrant tags.
2
2
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
+
3
7
4
8
#### 07/02/2016
5
9
Added multiline support to shell mode.
Original file line number Diff line number Diff line change @@ -213,6 +213,32 @@ ishell.ProgressBar().Display(display)
213
213
shell.SetHomeHistoryPath (" .ishell_history" )
214
214
```
215
215
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
+
216
242
### Example
217
243
Available [ here] ( https://github.com/abiosoft/ishell/blob/master/example/main.go ) .
218
244
``` sh
@@ -252,6 +278,7 @@ Library | Use
252
278
[ github.com/flynn-archive/go-shlex] ( http://github.com/flynn-archive/go-shlex ) | splitting input into command and args.
253
279
[ github.com/chzyer/readline] ( github.com/chzyer/readline ) | readline capabilities.
254
280
281
+
255
282
## Donate
256
283
```
257
284
bitcoin:1GTHYEDiy2C7RzXn5nY4wVRaEN2GvLjwZN
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ package main
3
3
import (
4
4
"errors"
5
5
"fmt"
6
+ "os"
6
7
"strings"
7
8
"time"
8
9
@@ -169,9 +170,13 @@ This is another line of it.
169
170
},
170
171
})
171
172
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
+ }
177
182
}
You can’t perform that action at this time.
0 commit comments