aboutsummaryrefslogtreecommitdiff
path: root/session.go
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2023-03-20 00:28:14 +0700
committerShulhan <ms@kilabit.info>2023-03-20 13:53:53 +0700
commitb7fc0aad9f394c99b9cfd258db6abb4ecee028a9 (patch)
treef6ab2efa3015be0e9bd92b8a2c7b8eaf2ff4375a /session.go
parent42e96adf2ea2bab6f173bd38eed49f30346867dd (diff)
downloadawwan-b7fc0aad9f394c99b9cfd258db6abb4ecee028a9.tar.xz
all: changes the line number arguments for "local" and "play" command
Previously, the "local" and "play" command only accept two kind of arguments: one argument for executing single line or two arguments for executing line range. There are no options to executing multiple single line, multiple line range, or combination of them. This changes make the both commands accept list of lines or line range where each separated by comma. For example, to execute multiple, different single lines awwan local 4,8,12 To execute multiple line range, awwan local 4-8,12-16 Or to execute multiple lines and line range, awwan local 4,8,10-12
Diffstat (limited to 'session.go')
-rw-r--r--session.go32
1 files changed, 23 insertions, 9 deletions
diff --git a/session.go b/session.go
index 8e3b64b..01f01c2 100644
--- a/session.go
+++ b/session.go
@@ -353,13 +353,13 @@ func (ses *Session) ExecLocal(req *Request, stmt *Statement) (err error) {
// executeRequires run the "#require:" statements from line 0 until
// the start argument in the local system.
-func (ses *Session) executeRequires(req *Request) (err error) {
+func (ses *Session) executeRequires(req *Request, pos linePosition) (err error) {
var (
- x int
stmt *Statement
+ x int64
)
- for x = 0; x < req.BeginAt; x++ {
+ for x = 0; x < pos.start; x++ {
stmt = req.script.requires[x]
if stmt == nil {
continue
@@ -375,10 +375,16 @@ func (ses *Session) executeRequires(req *Request) (err error) {
return nil
}
-func (ses *Session) executeScriptOnLocal(req *Request) {
- var err error
+func (ses *Session) executeScriptOnLocal(req *Request, pos linePosition) {
+ var max = int64(len(req.script.stmts))
+ if pos.start > max {
+ return
+ }
+ if pos.end == 0 {
+ pos.end = max - 1
+ }
- for x := req.BeginAt; x <= req.EndAt; x++ {
+ for x := pos.start; x <= pos.end; x++ {
stmt := req.script.stmts[x]
if stmt == nil {
continue
@@ -392,6 +398,7 @@ func (ses *Session) executeScriptOnLocal(req *Request) {
fmt.Fprintf(req.stdout, "\n>>> local: %3d: %s %s\n", x, stmt.cmd, stmt.args)
+ var err error
switch stmt.kind {
case statementKindDefault:
err = ses.ExecLocal(req, stmt)
@@ -411,10 +418,16 @@ func (ses *Session) executeScriptOnLocal(req *Request) {
}
}
-func (ses *Session) executeScriptOnRemote(req *Request) {
- var err error
+func (ses *Session) executeScriptOnRemote(req *Request, pos linePosition) {
+ var max = int64(len(req.script.stmts))
+ if pos.start > max {
+ return
+ }
+ if pos.end == 0 {
+ pos.end = max - 1
+ }
- for x := req.BeginAt; x <= req.EndAt; x++ {
+ for x := pos.start; x <= pos.end; x++ {
stmt := req.script.stmts[x]
if stmt == nil {
continue
@@ -429,6 +442,7 @@ func (ses *Session) executeScriptOnRemote(req *Request) {
fmt.Fprintf(req.stdout, "\n>>> %s: %3d: %s %s\n",
ses.sshClient, x, stmt.cmd, stmt.args)
+ var err error
switch stmt.kind {
case statementKindDefault:
err = ses.sshClient.Execute(string(stmt.raw))