Skip to content

Conversation

@tleonhardt
Copy link
Member

@tleonhardt tleonhardt commented Feb 9, 2018

Added two additional optional parameters to the cmd2.Cmd class init():

  • persistent_history_file - file path to load a persistent readline history from
  • persistent_history_length - max number of lines which will be written to the history file

If persistent_history_file is supplied and is non-empty, then at the beginning of its initialization, the cmd2.Cmd class attempts to expand this path and load readline history from this file. If the file isn't found, it just moves on. It also uses atexit to register saving the readline history to this file when the cmd2 application exits.

The persistent_history_file argument defaults to an empty string and thus by default the cmd2.Cmd application does NOT use a persistent readline history.

Included an example and info in the Sphinx docs.

Unrelated changes added to this PR:

  • Created CHANGELOG entry for 0.8.1 release
  • Added info to README about new sub-menu feature
  • Bumped version to 0.8.1

This closes #265.

- Including an example and info in the Sphinx docs

Also:
- Created CHANGELOG entry for 0.8.1 release
- Added info to README about new sub-menu feature
- Bumped version to 0.8.1

TODO:
- Added a unit test for the persistent readline history feature
@tleonhardt tleonhardt added this to the 0.8.1 milestone Feb 9, 2018
@tleonhardt tleonhardt self-assigned this Feb 9, 2018
@tleonhardt tleonhardt requested a review from kotfu February 9, 2018 03:14
@tleonhardt
Copy link
Member Author

tleonhardt commented Feb 9, 2018

@kotfu I can't figure out a good way to unit test readline history behavior to unit test this new persistent history feature.

I manually tested it and verified it works on Windows, Mac, and Linux as well as Python 2 and 3.

But I would prefer to have a unit test. Can you think of any way to unit test this?

@codecov
Copy link

codecov bot commented Feb 9, 2018

Codecov Report

Merging #270 into master will decrease coverage by 0.51%.
The diff coverage is 50%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #270      +/-   ##
==========================================
- Coverage   92.07%   91.56%   -0.52%     
==========================================
  Files           1        1              
  Lines        1413     1422       +9     
==========================================
+ Hits         1301     1302       +1     
- Misses        112      120       +8
Impacted Files Coverage Δ
cmd2.py 91.56% <50%> (-0.52%) ⬇️

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 4895d5d...f3c6b1b. Read the comment docs.

Added pexpect to modules required for running unit tests.

This opens the door for carefully crafted complex unit tests to verify intricate behavior.  Tests like this are somewhat painful to write and slow to execute.  However, they can enable testing complicated interactive behavior that we otherwise probably would not be able to test.
@tleonhardt
Copy link
Member Author

So the pexpect-based unit test works fine on my computer and I tested on both macOS and Linux. However, it doesn't work on TravisCI.

…acOS

- The Windows pexpect API is different from macOS or Linux
- On Travis CI, the test behaves as if readline isn't working on those machines
- The test runs fine when run on my system (on either macOS or Linux)
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.

Consider adding optional persistent history

2 participants