Skip to content

Commit 299c6ea

Browse files
committed
Don't try to load empty or non-existent startup script
1 parent 880bdd1 commit 299c6ea

2 files changed

Lines changed: 8 additions & 6 deletions

File tree

cmd2.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,7 +1052,9 @@ def __init__(self, completekey='tab', stdin=None, stdout=None, persistent_histor
10521052

10531053
# If a startup script is provided, then add it in the queue to load
10541054
if startup_script is not None:
1055-
self.cmdqueue.append('load {}'.format(startup_script))
1055+
startup_script = os.path.expanduser(startup_script)
1056+
if os.path.exists(startup_script) and os.path.getsize(startup_script) > 0:
1057+
self.cmdqueue.append('load {}'.format(startup_script))
10561058

10571059
############################################################################################################
10581060
# The following variables are used by tab-completion functions. They are reset each time complete() is run
@@ -2747,8 +2749,8 @@ def do_alias(self, arglist):
27472749
27482750
Usage: Usage: alias [name] | [<name> <value>]
27492751
Where:
2750-
name - name of the alias being looked up, added, or edited
2751-
value - what the alias will be resolved to (if adding or editing)
2752+
name - name of the alias being looked up, added, or replaced
2753+
value - what the alias will be resolved to (if adding or replacing)
27522754
this can contain spaces and does not need to be quoted
27532755
27542756
Without arguments, 'alias' prints a list of all aliases in a reusable form which
@@ -2780,7 +2782,7 @@ def do_alias(self, arglist):
27802782
if name in self.aliases:
27812783
self.poutput("alias {} {}".format(name, self.aliases[name]))
27822784
else:
2783-
self.perror("Alias '{}' not found".format(name), traceback_war=False)
2785+
self.perror("Alias {!r} not found".format(name), traceback_war=False)
27842786

27852787
# The user is creating an alias
27862788
else:
@@ -2796,7 +2798,7 @@ def do_alias(self, arglist):
27962798

27972799
# Set the alias
27982800
self.aliases[name] = value
2799-
self.poutput("Alias created")
2801+
self.poutput("Alias {!r} created".format(name))
28002802

28012803
def complete_alias(self, text, line, begidx, endidx):
28022804
""" Tab completion for alias """

tests/test_cmd2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1549,7 +1549,7 @@ def test_poutput_none(base_app):
15491549
def test_alias(base_app, capsys):
15501550
# Create the alias
15511551
out = run_cmd(base_app, 'alias fake pyscript')
1552-
assert out == normalize("Alias created")
1552+
assert out == normalize("Alias 'fake' created")
15531553

15541554
# Use the alias
15551555
run_cmd(base_app, 'fake')

0 commit comments

Comments
 (0)