aboutsummaryrefslogtreecommitdiff
path: root/statement.go
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2023-10-22 00:30:00 +0700
committerShulhan <ms@kilabit.info>2023-10-22 00:30:00 +0700
commit4411ca1953c95ddc013e47c55e87303b7290e2cc (patch)
treeb9223acea9f2379c004e0adf5acd343b98652d8d /statement.go
parent973bdb9666229f3df79c44d565012ce9c24a1f1f (diff)
downloadawwan-4411ca1953c95ddc013e47c55e87303b7290e2cc.tar.xz
all: rewrite method String in Statement
Instead of returning the string based on cmd and args values, return it based on its kind. In this way, the full line of magic command is returned before as is.
Diffstat (limited to 'statement.go')
-rw-r--r--statement.go32
1 files changed, 31 insertions, 1 deletions
diff --git a/statement.go b/statement.go
index 2bfc36c..ff59ca7 100644
--- a/statement.go
+++ b/statement.go
@@ -117,7 +117,37 @@ func ParseStatement(raw []byte) (stmt *Statement, err error) {
}
func (stmt *Statement) String() string {
- return fmt.Sprintf("%s%s %s", magicCmdGetPut[stmt.kind], stmt.cmd, strings.Join(stmt.args, " "))
+ var sb strings.Builder
+
+ switch stmt.kind {
+ case statementKindDefault:
+ sb.Write(stmt.raw)
+
+ case statementKindLocal:
+ sb.Write(cmdMagicLocal)
+ sb.Write(stmt.raw)
+
+ case statementKindGet, statementKindPut, statementKindSudoGet, statementKindSudoPut:
+ sb.Write(magicCmdGetPut[stmt.kind])
+ if len(stmt.owner) != 0 {
+ sb.WriteString(stmt.owner)
+ }
+ if stmt.mode != 0 {
+ sb.WriteByte('+')
+ sb.WriteString(strconv.FormatUint(uint64(stmt.mode), 8))
+ }
+ sb.WriteByte(' ')
+ sb.WriteString(stmt.args[0])
+ sb.WriteByte(' ')
+ sb.WriteString(stmt.args[1])
+
+ case statementKindRequire:
+ sb.Write(cmdMagicRequire)
+ sb.WriteByte(' ')
+ sb.Write(stmt.raw)
+ }
+
+ return sb.String()
}
// parseStatementGetPut parse the raw "#get" or "#put" statement.