Skip to content

Commit 8924397

Browse files
Simplify argv creation
1 parent 99b00fd commit 8924397

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/crystal/system/unix/process.cr

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -310,23 +310,24 @@ 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+
pathname = "/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]
324+
pathname = command
329325
end
326+
327+
argv_ary.concat(args) if args
328+
329+
argv = argv_ary.map(&.check_no_null_byte.to_unsafe)
330+
{pathname, argv.to_unsafe}
330331
end
331332

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

0 commit comments

Comments
 (0)