just-bash 0.1.5__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- just_bash/__init__.py +55 -0
- just_bash/ast/__init__.py +213 -0
- just_bash/ast/factory.py +320 -0
- just_bash/ast/types.py +953 -0
- just_bash/bash.py +220 -0
- just_bash/commands/__init__.py +23 -0
- just_bash/commands/argv/__init__.py +5 -0
- just_bash/commands/argv/argv.py +21 -0
- just_bash/commands/awk/__init__.py +5 -0
- just_bash/commands/awk/awk.py +1168 -0
- just_bash/commands/base64/__init__.py +5 -0
- just_bash/commands/base64/base64.py +138 -0
- just_bash/commands/basename/__init__.py +5 -0
- just_bash/commands/basename/basename.py +72 -0
- just_bash/commands/bash/__init__.py +5 -0
- just_bash/commands/bash/bash.py +188 -0
- just_bash/commands/cat/__init__.py +5 -0
- just_bash/commands/cat/cat.py +173 -0
- just_bash/commands/checksum/__init__.py +5 -0
- just_bash/commands/checksum/checksum.py +179 -0
- just_bash/commands/chmod/__init__.py +5 -0
- just_bash/commands/chmod/chmod.py +216 -0
- just_bash/commands/column/__init__.py +5 -0
- just_bash/commands/column/column.py +180 -0
- just_bash/commands/comm/__init__.py +5 -0
- just_bash/commands/comm/comm.py +150 -0
- just_bash/commands/compression/__init__.py +5 -0
- just_bash/commands/compression/compression.py +298 -0
- just_bash/commands/cp/__init__.py +5 -0
- just_bash/commands/cp/cp.py +149 -0
- just_bash/commands/curl/__init__.py +5 -0
- just_bash/commands/curl/curl.py +801 -0
- just_bash/commands/cut/__init__.py +5 -0
- just_bash/commands/cut/cut.py +327 -0
- just_bash/commands/date/__init__.py +5 -0
- just_bash/commands/date/date.py +258 -0
- just_bash/commands/diff/__init__.py +5 -0
- just_bash/commands/diff/diff.py +118 -0
- just_bash/commands/dirname/__init__.py +5 -0
- just_bash/commands/dirname/dirname.py +56 -0
- just_bash/commands/du/__init__.py +5 -0
- just_bash/commands/du/du.py +150 -0
- just_bash/commands/echo/__init__.py +5 -0
- just_bash/commands/echo/echo.py +125 -0
- just_bash/commands/env/__init__.py +5 -0
- just_bash/commands/env/env.py +163 -0
- just_bash/commands/expand/__init__.py +5 -0
- just_bash/commands/expand/expand.py +299 -0
- just_bash/commands/expr/__init__.py +5 -0
- just_bash/commands/expr/expr.py +273 -0
- just_bash/commands/file/__init__.py +5 -0
- just_bash/commands/file/file.py +274 -0
- just_bash/commands/find/__init__.py +5 -0
- just_bash/commands/find/find.py +623 -0
- just_bash/commands/fold/__init__.py +5 -0
- just_bash/commands/fold/fold.py +160 -0
- just_bash/commands/grep/__init__.py +5 -0
- just_bash/commands/grep/grep.py +418 -0
- just_bash/commands/head/__init__.py +5 -0
- just_bash/commands/head/head.py +167 -0
- just_bash/commands/help/__init__.py +5 -0
- just_bash/commands/help/help.py +67 -0
- just_bash/commands/hostname/__init__.py +5 -0
- just_bash/commands/hostname/hostname.py +21 -0
- just_bash/commands/html_to_markdown/__init__.py +5 -0
- just_bash/commands/html_to_markdown/html_to_markdown.py +191 -0
- just_bash/commands/join/__init__.py +5 -0
- just_bash/commands/join/join.py +252 -0
- just_bash/commands/jq/__init__.py +5 -0
- just_bash/commands/jq/jq.py +280 -0
- just_bash/commands/ln/__init__.py +5 -0
- just_bash/commands/ln/ln.py +127 -0
- just_bash/commands/ls/__init__.py +5 -0
- just_bash/commands/ls/ls.py +280 -0
- just_bash/commands/mkdir/__init__.py +5 -0
- just_bash/commands/mkdir/mkdir.py +92 -0
- just_bash/commands/mv/__init__.py +5 -0
- just_bash/commands/mv/mv.py +142 -0
- just_bash/commands/nl/__init__.py +5 -0
- just_bash/commands/nl/nl.py +180 -0
- just_bash/commands/od/__init__.py +5 -0
- just_bash/commands/od/od.py +157 -0
- just_bash/commands/paste/__init__.py +5 -0
- just_bash/commands/paste/paste.py +100 -0
- just_bash/commands/printf/__init__.py +5 -0
- just_bash/commands/printf/printf.py +157 -0
- just_bash/commands/pwd/__init__.py +5 -0
- just_bash/commands/pwd/pwd.py +23 -0
- just_bash/commands/read/__init__.py +5 -0
- just_bash/commands/read/read.py +185 -0
- just_bash/commands/readlink/__init__.py +5 -0
- just_bash/commands/readlink/readlink.py +86 -0
- just_bash/commands/registry.py +844 -0
- just_bash/commands/rev/__init__.py +5 -0
- just_bash/commands/rev/rev.py +74 -0
- just_bash/commands/rg/__init__.py +5 -0
- just_bash/commands/rg/rg.py +1048 -0
- just_bash/commands/rm/__init__.py +5 -0
- just_bash/commands/rm/rm.py +106 -0
- just_bash/commands/search_engine/__init__.py +13 -0
- just_bash/commands/search_engine/matcher.py +170 -0
- just_bash/commands/search_engine/regex.py +159 -0
- just_bash/commands/sed/__init__.py +5 -0
- just_bash/commands/sed/sed.py +863 -0
- just_bash/commands/seq/__init__.py +5 -0
- just_bash/commands/seq/seq.py +190 -0
- just_bash/commands/shell/__init__.py +5 -0
- just_bash/commands/shell/shell.py +206 -0
- just_bash/commands/sleep/__init__.py +5 -0
- just_bash/commands/sleep/sleep.py +62 -0
- just_bash/commands/sort/__init__.py +5 -0
- just_bash/commands/sort/sort.py +411 -0
- just_bash/commands/split/__init__.py +5 -0
- just_bash/commands/split/split.py +237 -0
- just_bash/commands/sqlite3/__init__.py +5 -0
- just_bash/commands/sqlite3/sqlite3_cmd.py +505 -0
- just_bash/commands/stat/__init__.py +5 -0
- just_bash/commands/stat/stat.py +150 -0
- just_bash/commands/strings/__init__.py +5 -0
- just_bash/commands/strings/strings.py +150 -0
- just_bash/commands/tac/__init__.py +5 -0
- just_bash/commands/tac/tac.py +158 -0
- just_bash/commands/tail/__init__.py +5 -0
- just_bash/commands/tail/tail.py +180 -0
- just_bash/commands/tar/__init__.py +5 -0
- just_bash/commands/tar/tar.py +1067 -0
- just_bash/commands/tee/__init__.py +5 -0
- just_bash/commands/tee/tee.py +63 -0
- just_bash/commands/timeout/__init__.py +5 -0
- just_bash/commands/timeout/timeout.py +188 -0
- just_bash/commands/touch/__init__.py +5 -0
- just_bash/commands/touch/touch.py +91 -0
- just_bash/commands/tr/__init__.py +5 -0
- just_bash/commands/tr/tr.py +297 -0
- just_bash/commands/tree/__init__.py +5 -0
- just_bash/commands/tree/tree.py +139 -0
- just_bash/commands/true/__init__.py +5 -0
- just_bash/commands/true/true.py +32 -0
- just_bash/commands/uniq/__init__.py +5 -0
- just_bash/commands/uniq/uniq.py +323 -0
- just_bash/commands/wc/__init__.py +5 -0
- just_bash/commands/wc/wc.py +169 -0
- just_bash/commands/which/__init__.py +5 -0
- just_bash/commands/which/which.py +52 -0
- just_bash/commands/xan/__init__.py +5 -0
- just_bash/commands/xan/xan.py +1663 -0
- just_bash/commands/xargs/__init__.py +5 -0
- just_bash/commands/xargs/xargs.py +136 -0
- just_bash/commands/yq/__init__.py +5 -0
- just_bash/commands/yq/yq.py +848 -0
- just_bash/fs/__init__.py +29 -0
- just_bash/fs/in_memory_fs.py +621 -0
- just_bash/fs/mountable_fs.py +504 -0
- just_bash/fs/overlay_fs.py +894 -0
- just_bash/fs/read_write_fs.py +455 -0
- just_bash/interpreter/__init__.py +37 -0
- just_bash/interpreter/builtins/__init__.py +92 -0
- just_bash/interpreter/builtins/alias.py +154 -0
- just_bash/interpreter/builtins/cd.py +76 -0
- just_bash/interpreter/builtins/control.py +127 -0
- just_bash/interpreter/builtins/declare.py +336 -0
- just_bash/interpreter/builtins/export.py +56 -0
- just_bash/interpreter/builtins/let.py +44 -0
- just_bash/interpreter/builtins/local.py +57 -0
- just_bash/interpreter/builtins/mapfile.py +152 -0
- just_bash/interpreter/builtins/misc.py +378 -0
- just_bash/interpreter/builtins/readonly.py +80 -0
- just_bash/interpreter/builtins/set.py +234 -0
- just_bash/interpreter/builtins/shopt.py +201 -0
- just_bash/interpreter/builtins/source.py +136 -0
- just_bash/interpreter/builtins/test.py +290 -0
- just_bash/interpreter/builtins/unset.py +53 -0
- just_bash/interpreter/conditionals.py +387 -0
- just_bash/interpreter/control_flow.py +381 -0
- just_bash/interpreter/errors.py +116 -0
- just_bash/interpreter/expansion.py +1156 -0
- just_bash/interpreter/interpreter.py +813 -0
- just_bash/interpreter/types.py +134 -0
- just_bash/network/__init__.py +1 -0
- just_bash/parser/__init__.py +39 -0
- just_bash/parser/lexer.py +948 -0
- just_bash/parser/parser.py +2162 -0
- just_bash/py.typed +0 -0
- just_bash/query_engine/__init__.py +83 -0
- just_bash/query_engine/builtins/__init__.py +1283 -0
- just_bash/query_engine/evaluator.py +578 -0
- just_bash/query_engine/parser.py +525 -0
- just_bash/query_engine/tokenizer.py +329 -0
- just_bash/query_engine/types.py +373 -0
- just_bash/types.py +180 -0
- just_bash-0.1.5.dist-info/METADATA +410 -0
- just_bash-0.1.5.dist-info/RECORD +193 -0
- just_bash-0.1.5.dist-info/WHEEL +4 -0
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"""Xargs command implementation."""
|
|
2
|
+
|
|
3
|
+
from ...types import CommandContext, ExecResult
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class XargsCommand:
|
|
7
|
+
"""The xargs command."""
|
|
8
|
+
|
|
9
|
+
name = "xargs"
|
|
10
|
+
|
|
11
|
+
async def execute(self, args: list[str], ctx: CommandContext) -> ExecResult:
|
|
12
|
+
"""Execute the xargs command."""
|
|
13
|
+
batch_size = None
|
|
14
|
+
replace_str = None
|
|
15
|
+
delimiter = None
|
|
16
|
+
null_sep = False
|
|
17
|
+
no_run_empty = False
|
|
18
|
+
verbose = False
|
|
19
|
+
command: list[str] = []
|
|
20
|
+
|
|
21
|
+
i = 0
|
|
22
|
+
while i < len(args):
|
|
23
|
+
arg = args[i]
|
|
24
|
+
if arg == "-n" and i + 1 < len(args):
|
|
25
|
+
i += 1
|
|
26
|
+
batch_size = int(args[i])
|
|
27
|
+
elif arg == "-I" and i + 1 < len(args):
|
|
28
|
+
i += 1
|
|
29
|
+
replace_str = args[i]
|
|
30
|
+
elif arg == "-d" and i + 1 < len(args):
|
|
31
|
+
i += 1
|
|
32
|
+
delimiter = args[i]
|
|
33
|
+
elif arg == "-0":
|
|
34
|
+
null_sep = True
|
|
35
|
+
elif arg == "-r" or arg == "--no-run-if-empty":
|
|
36
|
+
no_run_empty = True
|
|
37
|
+
elif arg == "-t":
|
|
38
|
+
verbose = True
|
|
39
|
+
elif arg == "-P":
|
|
40
|
+
# Parallel - skip the value, we don't really parallelize
|
|
41
|
+
i += 1
|
|
42
|
+
elif arg.startswith("-"):
|
|
43
|
+
pass # Ignore unknown options
|
|
44
|
+
else:
|
|
45
|
+
command = args[i:]
|
|
46
|
+
break
|
|
47
|
+
i += 1
|
|
48
|
+
|
|
49
|
+
# Default command is echo
|
|
50
|
+
if not command:
|
|
51
|
+
command = ["echo"]
|
|
52
|
+
|
|
53
|
+
# Parse input
|
|
54
|
+
content = ctx.stdin
|
|
55
|
+
if null_sep:
|
|
56
|
+
items = [item for item in content.split("\0") if item]
|
|
57
|
+
elif delimiter:
|
|
58
|
+
if delimiter == "\\n":
|
|
59
|
+
delimiter = "\n"
|
|
60
|
+
elif delimiter == "\\t":
|
|
61
|
+
delimiter = "\t"
|
|
62
|
+
items = [item for item in content.split(delimiter) if item]
|
|
63
|
+
else:
|
|
64
|
+
# Default: split on whitespace and newlines
|
|
65
|
+
items = content.split()
|
|
66
|
+
|
|
67
|
+
# Handle empty input
|
|
68
|
+
if not items:
|
|
69
|
+
if no_run_empty:
|
|
70
|
+
return ExecResult(stdout="", stderr="", exit_code=0)
|
|
71
|
+
items = [""]
|
|
72
|
+
|
|
73
|
+
# Execute commands
|
|
74
|
+
stdout_parts = []
|
|
75
|
+
stderr_parts = []
|
|
76
|
+
exit_code = 0
|
|
77
|
+
|
|
78
|
+
if replace_str:
|
|
79
|
+
# Run command once per item with replacement
|
|
80
|
+
for item in items:
|
|
81
|
+
cmd = [c.replace(replace_str, item) for c in command]
|
|
82
|
+
result = await self._run_command(cmd, ctx, verbose)
|
|
83
|
+
stdout_parts.append(result.stdout)
|
|
84
|
+
stderr_parts.append(result.stderr)
|
|
85
|
+
if result.exit_code != 0:
|
|
86
|
+
exit_code = result.exit_code
|
|
87
|
+
elif batch_size:
|
|
88
|
+
# Run command in batches
|
|
89
|
+
for j in range(0, len(items), batch_size):
|
|
90
|
+
batch = items[j:j + batch_size]
|
|
91
|
+
cmd = command + batch
|
|
92
|
+
result = await self._run_command(cmd, ctx, verbose)
|
|
93
|
+
stdout_parts.append(result.stdout)
|
|
94
|
+
stderr_parts.append(result.stderr)
|
|
95
|
+
if result.exit_code != 0:
|
|
96
|
+
exit_code = result.exit_code
|
|
97
|
+
else:
|
|
98
|
+
# Run command once with all items
|
|
99
|
+
cmd = command + items
|
|
100
|
+
result = await self._run_command(cmd, ctx, verbose)
|
|
101
|
+
stdout_parts.append(result.stdout)
|
|
102
|
+
stderr_parts.append(result.stderr)
|
|
103
|
+
exit_code = result.exit_code
|
|
104
|
+
|
|
105
|
+
return ExecResult(
|
|
106
|
+
stdout="".join(stdout_parts),
|
|
107
|
+
stderr="".join(stderr_parts),
|
|
108
|
+
exit_code=exit_code,
|
|
109
|
+
)
|
|
110
|
+
|
|
111
|
+
async def _run_command(
|
|
112
|
+
self, cmd: list[str], ctx: CommandContext, verbose: bool
|
|
113
|
+
) -> ExecResult:
|
|
114
|
+
"""Run a command."""
|
|
115
|
+
if verbose:
|
|
116
|
+
pass # Would print command to stderr
|
|
117
|
+
|
|
118
|
+
# Quote arguments properly for shell execution
|
|
119
|
+
def quote(s: str) -> str:
|
|
120
|
+
if not s or any(c in s for c in " \t\n'\"\\$`!"):
|
|
121
|
+
# Use single quotes and escape any single quotes
|
|
122
|
+
return "'" + s.replace("'", "'\"'\"'") + "'"
|
|
123
|
+
return s
|
|
124
|
+
|
|
125
|
+
cmd_str = " ".join(quote(c) for c in cmd)
|
|
126
|
+
|
|
127
|
+
# Execute using ctx.exec
|
|
128
|
+
if ctx.exec:
|
|
129
|
+
return await ctx.exec(cmd_str, {"cwd": ctx.cwd})
|
|
130
|
+
else:
|
|
131
|
+
# Fallback if exec not available
|
|
132
|
+
return ExecResult(
|
|
133
|
+
stdout="",
|
|
134
|
+
stderr="xargs: cannot execute commands\n",
|
|
135
|
+
exit_code=126,
|
|
136
|
+
)
|