summaryrefslogtreecommitdiff
path: root/internal/askcli/task_scope.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/askcli/task_scope.go')
-rw-r--r--internal/askcli/task_scope.go63
1 files changed, 63 insertions, 0 deletions
diff --git a/internal/askcli/task_scope.go b/internal/askcli/task_scope.go
new file mode 100644
index 0000000..42dd022
--- /dev/null
+++ b/internal/askcli/task_scope.go
@@ -0,0 +1,63 @@
+package askcli
+
+import "context"
+
+type taskScopeMode int
+
+const (
+ taskScopeAgent taskScopeMode = iota
+ taskScopeNoAgent
+)
+
+type taskScopeContextKey struct{}
+
+func contextWithTaskScope(ctx context.Context, scope taskScopeMode) context.Context {
+ if scope == taskScopeAgent {
+ return ctx
+ }
+ return context.WithValue(ctx, taskScopeContextKey{}, scope)
+}
+
+func taskScopeFromContext(ctx context.Context) taskScopeMode {
+ if ctx == nil {
+ return taskScopeAgent
+ }
+ scope, ok := ctx.Value(taskScopeContextKey{}).(taskScopeMode)
+ if !ok {
+ return taskScopeAgent
+ }
+ return scope
+}
+
+func taskScopeFilter(scope taskScopeMode) string {
+ if scope == taskScopeNoAgent {
+ return "-agent"
+ }
+ return "+agent"
+}
+
+func parseTaskScopePrefix(args []string) (taskScopeMode, []string) {
+ if len(args) == 0 {
+ return taskScopeAgent, nil
+ }
+ if isTaskScopePrefix(args[0]) {
+ return taskScopeNoAgent, args[1:]
+ }
+ return taskScopeAgent, args
+}
+
+func isTaskScopePrefix(arg string) bool {
+ switch arg {
+ case "na", "no-agent":
+ return true
+ default:
+ return false
+ }
+}
+
+func trimTaskScopePrefix(args []string) []string {
+ if len(args) == 0 || !isTaskScopePrefix(args[0]) {
+ return args
+ }
+ return args[1:]
+}