Skip to content

Check if name is in self.get_names() before removing#272

Merged
tleonhardt merged 1 commit intopython-cmd2:masterfrom
bsquizz:master
Feb 12, 2018
Merged

Check if name is in self.get_names() before removing#272
tleonhardt merged 1 commit intopython-cmd2:masterfrom
bsquizz:master

Conversation

@bsquizz
Copy link
Copy Markdown
Contributor

@bsquizz bsquizz commented Feb 12, 2018

This is to avoid hitting ERROR: Invalid syntax: list.remove(x): x not in list if a command is added to exclude_from_help which does not exist in the instance.

I ran into this when trying to use 2 nested prompts each with different exclude_from_help lists. Once the second prompt was instantiated, the 'help' command is updated at the class level, so the command list may now be inaccurate for other instances.

Perhaps it should be considered to change exclude_from_help to an instance variable.

@bsquizz bsquizz requested a review from tleonhardt as a code owner February 12, 2018 19:53
@codecov
Copy link
Copy Markdown

codecov Bot commented Feb 12, 2018

Codecov Report

Merging #272 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #272      +/-   ##
==========================================
+ Coverage   91.56%   91.56%   +<.01%     
==========================================
  Files           1        1              
  Lines        1422     1423       +1     
==========================================
+ Hits         1302     1303       +1     
  Misses        120      120
Impacted Files Coverage Δ
cmd2.py 91.56% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4a765e1...d369123. Read the comment docs.

Comment thread cmd2.py
# Remove any command names which are explicitly excluded from the help menu
for name in self.exclude_from_help:
names.remove(name)
if name in names:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice ruggedization. Thanks for the PR!

@tleonhardt
Copy link
Copy Markdown
Member

I agree, exclude_from_help should probably be an instance variable. Now that we are nesting cmd2.Cmd instances to create-submenus, we should probably revisit what attributes should be made instance variables in general. I'll create an Issue for that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants