Skip to content

Conversation

kmvanbrunt
Copy link
Member

Added --clear argument to history command
Added better error checking when loading readline history file
Improved some error messages
Changed IOError usages to OSError since they were merged in Python 3.3.

Added better error checking when loading readline history file
Improved some error messages
Changed IOError usages to OSError since they were merged in Python 3.3.
@codecov
Copy link

codecov bot commented Jul 12, 2018

Codecov Report

Merging #467 into master will decrease coverage by 0.35%.
The diff coverage is 44.73%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #467      +/-   ##
==========================================
- Coverage    90.2%   89.84%   -0.36%     
==========================================
  Files          10       10              
  Lines        2736     2758      +22     
==========================================
+ Hits         2468     2478      +10     
- Misses        268      280      +12
Impacted Files Coverage Δ
cmd2/utils.py 98.43% <ø> (ø) ⬆️
cmd2/cmd2.py 89.83% <44.73%> (-0.66%) ⬇️

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 ea7a4bb...4a233b8. Read the comment docs.

@tleonhardt tleonhardt added this to the 0.9.3 milestone Jul 12, 2018
Copy link
Member

@tleonhardt tleonhardt left a comment

Choose a reason for hiding this comment

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

Looks good to me

# than trying to open the file with write access since readline's underlying function needs to
# create a temporary file in the same directory and may not have permission.
readline.set_history_length(persistent_history_length)
readline.write_history_file(persistent_history_file)
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for adding better error checking to make sure the user can actually write to the persistent history file.

readline.read_history_file(persistent_history_file)
except FileNotFoundError:
pass
except OSError as ex:
Copy link
Member

Choose a reason for hiding this comment

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

This is a good change since various exceptions got merged into OSError in Python 3.3 and we no longer support earlier versions of Python

readline.set_history_length(persistent_history_length)
readline.write_history_file(persistent_history_file)
except OSError as ex:
self.perror("readline cannot write persistent history file '{}': {}".
Copy link
Member

Choose a reason for hiding this comment

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

Yeah, we should have had an error message in this case. Thanks for adding it.

history_parser_group.add_argument('-s', '--script', action='store_true', help='script format; no separation lines')
history_parser_group.add_argument('-o', '--output-file', metavar='FILE', help='output commands to a script file')
history_parser_group.add_argument('-t', '--transcript', help='output commands and results to a transcript file')
history_parser_group.add_argument('-c', '--clear', action="store_true", help='clears all history')
Copy link
Member

Choose a reason for hiding this comment

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

Nice addition

# Make sure expanded_path points to a file
if not os.path.isfile(expanded_path):
self.perror('{} does not exist or is not a file'.format(expanded_path), traceback_war=False)
self.perror("'{}' is not a file".format(expanded_path), traceback_war=False)
Copy link
Member

Choose a reason for hiding this comment

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

Could alternatively use {!r}, but this is fine

output = run_cmd(base_app, 'history -r 1')
assert output == expected

def test_history_clear(base_app):
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for adding unit tests

@tleonhardt
Copy link
Member

@kmvanbrunt Better code coverage of new/added code would be nice. But this PR looks fine to me.

@kmvanbrunt kmvanbrunt merged commit 5d2133a into master Jul 12, 2018
@kmvanbrunt kmvanbrunt deleted the history branch July 12, 2018 05:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants