mirror of
https://github.com/powerline/powerline.git
synced 2025-07-30 01:05:42 +02:00
Improve argument handling in powerline script
Modules can now be any string, and an informative error message will be written to sys.stdout if the module doesn't exist. The `last_pipe_status` argument will also automatically be split into a list.
This commit is contained in:
parent
5db6f47562
commit
29793259e1
@ -7,10 +7,9 @@ last_status.requires_powerline_segment_info = True
|
|||||||
|
|
||||||
|
|
||||||
def last_pipe_status(segment_info):
|
def last_pipe_status(segment_info):
|
||||||
pipe_status = [int(status) for status in segment_info.last_pipe_status.split()]
|
if any(segment_info.last_pipe_status):
|
||||||
if any(pipe_status):
|
|
||||||
return [{"contents": str(status), "highlight_group": "exit_fail" if status else "exit_success"}
|
return [{"contents": str(status), "highlight_group": "exit_fail" if status else "exit_success"}
|
||||||
for status in pipe_status]
|
for status in segment_info.last_pipe_status]
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
last_pipe_status.requires_powerline_segment_info = True
|
last_pipe_status.requires_powerline_segment_info = True
|
||||||
|
@ -14,10 +14,10 @@ except ImportError:
|
|||||||
parser = argparse.ArgumentParser(description=__doc__)
|
parser = argparse.ArgumentParser(description=__doc__)
|
||||||
parser.add_argument('ext', nargs=1)
|
parser.add_argument('ext', nargs=1)
|
||||||
parser.add_argument('side', nargs='?', choices=('left', 'right'))
|
parser.add_argument('side', nargs='?', choices=('left', 'right'))
|
||||||
parser.add_argument('-r', '--renderer_module', choices=('shell', 'zsh_prompt', 'tmux'))
|
parser.add_argument('-r', '--renderer_module', metavar='MODULE', type=str)
|
||||||
parser.add_argument('-w', '--width', type=int)
|
parser.add_argument('-w', '--width', type=int)
|
||||||
parser.add_argument('--last_exit_code', type=int, metavar='INT')
|
parser.add_argument('--last_exit_code', metavar='INT', type=int)
|
||||||
parser.add_argument('--last_pipe_status', metavar='LIST')
|
parser.add_argument('--last_pipe_status', metavar='LIST', default='', type=lambda s: [int(status) for status in s.split()])
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user