Skip to content

Commit

Permalink
pycrictl: fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
hanxueluo committed Dec 12, 2021
1 parent 19cddb1 commit 7258d52
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions pycrictl
Original file line number Diff line number Diff line change
Expand Up @@ -460,24 +460,24 @@ class DockerExecutor(object):
]).split() + opt.raw

if action == "exec":
args.insert(2, "-it")
args.insert(3, "-it")
if not option.raw:
args += ["bash"]
if action == "run":
if action == "create":
args.insert(3, "--rm")
if option.raw:
args.insert(4, "-it")
args.insert(5, "--entrypoint")
args.insert(6, " ".join(option.raw))
opt = CmdOption([])

args.pop(1) # remove kind before execute, crictl only
Utility.print_to_stderr(" ".join(args))
use_stdout = action in ["exec", "logs", "stats", "top", "prune", "push", "pull", "run"]
try:
dec = DockerExtraCommand(kind, action, resource, opt, self.cache)
yes, code, out, err = dec.run()
if not yes:
args.pop(1) # remove kind before execute, crictl only
code, out, err = Utility.execute(args, use_stdout)
except KeyboardInterrupt:
code = 1
Expand Down Expand Up @@ -506,7 +506,7 @@ class DockerExecutor(object):
return action in ["prune", "repo"]

def risky_for_batch(self, action):
return action == "rm"
return action in ["rm", "rmi", "rmp", "stop", "stopp"]

def select_by_lineno(self, lines, linenos):
if not lines:
Expand Down Expand Up @@ -581,7 +581,7 @@ class DockerExecutor(object):
resource = " ".join(resources)

option = self.get_option(option.raw)
if not resource:
if not resource and not option.has("-h"):
if not self.accept_no_resource(action):
action = get_list_action(kind)
option = self.get_option([])
Expand Down Expand Up @@ -650,6 +650,11 @@ def main(argv):
kind = "pod"
else:
pass # default kind = container
# fix action cmd
if action in ["ins", "rm", "stop", "run", "inspect"]:
if action == "ins": action = "inspect"
if kind == "image": action = action + "i"
if kind == "pod": action = action + "p"

if argv and argv[-1][0] != "-":
resource = argv.pop()
Expand Down

0 comments on commit 7258d52

Please sign in to comment.