Skip to content

Commit 8cf0c48

Browse files
Simplify argv creation
1 parent 7a9e2fd commit 8cf0c48

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/crystal/system/unix/process.cr

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -310,23 +310,23 @@ struct Crystal::System::Process
310310
def self.prepare_args(command : String, args : Enumerable(String)?, shell : Bool) : {String, UInt8**}
311311
if shell
312312
command = %(#{command} "${@}") unless command.includes?(' ')
313-
shell_args = ["/bin/sh", "-c", command, "sh"]
313+
argv_ary = ["/bin/sh", "-c", command, "sh"]
314314

315315
if args
316316
unless command.includes?(%("${@}"))
317317
raise ArgumentError.new(%(Can't specify arguments in both command and args without including "${@}" into your command))
318318
end
319-
320-
shell_args.concat(args)
321319
end
322320

323-
{"/bin/sh", shell_args.map(&.check_no_null_byte.to_unsafe).to_unsafe}
321+
command = "/bin/sh"
324322
else
325-
command_args = [command]
326-
command_args.concat(args) if args
327-
328-
{command, command_args.map(&.check_no_null_byte.to_unsafe).to_unsafe}
323+
argv_ary = [command]
329324
end
325+
326+
argv_ary.concat(args) if args
327+
328+
argv = argv_ary.map(&.check_no_null_byte.to_unsafe)
329+
{command, argv.to_unsafe}
330330
end
331331

332332
private def self.try_replace(command_args, env, clear_env, input, output, error, chdir)

0 commit comments

Comments
 (0)