Skip to content

Commit

Permalink
Removed the default command
Browse files Browse the repository at this point in the history
Turns out, the default command was confusing to new users and old
developers alike, at least in it's current form.

Example:
with default_command = calendar `khal -a home DATE` would not work as
intended.

We might bring this back if click properly supports it though.

For now, you might want to use set up an alias like
`alias kal='khal calendar'.

fix pimutils#648
  • Loading branch information
geier committed Jun 13, 2017
1 parent 6a51e2d commit f8d9135
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 64 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ Package maintainers and users who have to manually update their installation
may want to subscribe to `GitHub's tag feed
<https://github.com/geier/khal/tags.atom>`_.

0.10.0
======
not released yet

* CHANGE removed default command

0.9.6
=====
released 2017-06-13
Expand Down
1 change: 0 additions & 1 deletion khal.conf.sample
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ longdatetimeformat = %d.%m.%Y %H:%M
firstweekday = 0

[default]
default_command = calendar
default_calendar = home
timedelta = 2 # the default timedelta that list uses
highlight_event_days = True # the default is False
10 changes: 1 addition & 9 deletions khal/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def stringify_conf(conf):


def _get_cli():
@click.group(invoke_without_command=True)
@click.group()
@global_options
@click.pass_context
def cli(ctx):
Expand All @@ -244,14 +244,6 @@ def cli(ctx):
# under FreeBSD, which is still nicer than the default
setproctitle('khal')

if not ctx.invoked_subcommand:
command = ctx.obj['conf']['default']['default_command']
if command:
ctx.invoke(cli.commands[command])
else:
click.echo(ctx.get_help())
ctx.exit(1)

@cli.command()
@multi_calendar_option
@click.option('--format', '-f',
Expand Down
3 changes: 0 additions & 3 deletions khal/settings/khal.spec
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,6 @@ quit = force_list(default=list('q', 'Q'))
# Some default values and behaviors are set here.
[default]

# Command to be executed if no command is given when executing khal.
default_command = option('calendar', 'list', 'interactive', 'printformats', 'printcalendars', 'printics', '', default='calendar')

# The calendar to use if none is specified for some operation (e.g. if adding a
# new event). If this is not set, such operations require an explicit value.
default_calendar = string(default=None)
Expand Down
1 change: 0 additions & 1 deletion khal/settings/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ def config_checks(
}

# get color from config if not defined in vdir

if calendar['color'] is None and vdir in vdir_colors_from_config:
logger.debug("using collection's color for {}".format(vdir))
calendar['color'] = vdir_colors_from_config[vdir]
Expand Down
81 changes: 34 additions & 47 deletions tests/cli_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,14 @@ def runner(tmpdir, monkeypatch):
monkeypatch.setattr('xdg.BaseDirectory.xdg_config_home', str(xdg_config_home))
monkeypatch.setattr('xdg.BaseDirectory.xdg_config_dirs', [str(xdg_config_home)])

def inner(default_command='list', print_new=False, default_calendar=True, days=2,
**kwargs):
def inner(print_new=False, default_calendar=True, days=2, **kwargs):
if default_calendar:
default_calendar = 'default_calendar = one'
else:
default_calendar = ''
if not os.path.exists(str(xdg_config_home.join('khal'))):
os.makedirs(str(xdg_config_home.join('khal')))
config_file.write(config_template.format(
default_command=default_command,
delta=str(days) + 'd',
calpath=str(calendar), calpath2=str(calendar2), calpath3=str(calendar3),
default_calendar=default_calendar,
Expand Down Expand Up @@ -96,7 +94,6 @@ def inner(default_command='list', print_new=False, default_calendar=True, days=2
firstweekday = 0
[default]
default_command = {default_command}
{default_calendar}
timedelta = {delta}
print_new = {print_new}
Expand All @@ -107,11 +104,11 @@ def inner(default_command='list', print_new=False, default_calendar=True, days=2


def test_direct_modification(runner):
runner = runner(default_command='list')
runner = runner()

result = runner.invoke(main_khal, ['list'])
assert not result.exception
assert result.output == 'No events\n'
assert not result.exception

cal_dt = _get_text('event_dt_simple')
event = runner.calendars['one'].join('test.ics')
Expand All @@ -129,9 +126,8 @@ def test_direct_modification(runner):


def test_simple(runner):
runner = runner(default_command='list', days=2)

result = runner.invoke(main_khal)
runner = runner(days=2)
result = runner.invoke(main_khal, ['list'])
assert not result.exception
assert result.output == 'No events\n'

Expand All @@ -141,7 +137,7 @@ def test_simple(runner):
assert result.output == ''
assert not result.exception

result = runner.invoke(main_khal)
result = runner.invoke(main_khal, ['list'])
print(result.output)
assert 'myevent' in result.output
assert '18:00' in result.output
Expand All @@ -151,20 +147,19 @@ def test_simple(runner):


def test_simple_color(runner):
runner = runner(default_command='list', days=2)

runner = runner(days=2)
now = datetime.datetime.now().strftime('%d.%m.%Y')
result = runner.invoke(main_khal, 'new {} 18:00 myevent'.format(now).split())
assert result.output == ''
assert not result.exception

result = runner.invoke(main_khal, color=True)
result = runner.invoke(main_khal, ['list'], color=True)
assert not result.exception
assert '\x1b[34m' in result.output


def test_days(runner):
runner = runner(default_command='list', days=9)
runner = runner(days=9)

when = (datetime.datetime.now() + timedelta(days=7)).strftime('%d.%m.%Y')
result = runner.invoke(main_khal, 'new {} 18:00 nextweek'.format(when).split())
Expand All @@ -176,7 +171,7 @@ def test_days(runner):
assert result.output == ''
assert not result.exception

result = runner.invoke(main_khal)
result = runner.invoke(main_khal, ['list'])
assert 'nextweek' in result.output
assert 'nextmonth' not in result.output
assert '18:00' in result.output
Expand All @@ -185,7 +180,7 @@ def test_days(runner):

def test_notstarted(runner):
with freeze_time('2015-6-1 15:00'):
runner = runner(default_command='calendar', days=2)
runner = runner(days=2)
for command in [
'new 30.5.2015 5.6.2015 long event',
'new 2.6.2015 4.6.2015 two day event',
Expand Down Expand Up @@ -248,8 +243,8 @@ def test_notstarted(runner):

def test_calendar(runner):
with freeze_time('2015-6-1'):
runner = runner(default_command='calendar', days=0)
result = runner.invoke(main_khal)
runner = runner(days=0)
result = runner.invoke(main_khal, ['calendar'])
assert not result.exception
assert result.exit_code == 0
output = '\n'.join([
Expand All @@ -275,8 +270,8 @@ def test_calendar(runner):

def test_long_calendar(runner):
with freeze_time('2015-6-1'):
runner = runner(default_command='calendar', days=100)
result = runner.invoke(main_khal)
runner = runner(days=100)
result = runner.invoke(main_khal, ['calendar'])
assert not result.exception
assert result.exit_code == 0
output = '\n'.join([
Expand Down Expand Up @@ -305,24 +300,16 @@ def test_long_calendar(runner):


def test_default_command_empty(runner):
runner = runner(default_command='', days=2)
runner = runner(days=2)

result = runner.invoke(main_khal)
assert result.exception
assert result.exit_code == 1
assert result.exit_code == 2
assert result.output.startswith('Usage: ')


def test_default_command_nonempty(runner):
runner = runner(default_command='list', days=2)

result = runner.invoke(main_khal)
assert not result.exception
assert result.output == 'No events\n'


def test_invalid_calendar(runner):
runner = runner(default_command='', days=2)
runner = runner(days=2)
result = runner.invoke(
main_khal, ['new'] + '-a one 18:00 myevent'.split())
assert not result.exception
Expand All @@ -334,7 +321,7 @@ def test_invalid_calendar(runner):


def test_attach_calendar(runner):
runner = runner(default_command='calendar', days=2)
runner = runner(days=2)
result = runner.invoke(main_khal, ['printcalendars'])
assert set(result.output.split('\n')[:3]) == set(['one', 'two', 'three'])
assert not result.exception
Expand All @@ -351,19 +338,19 @@ def test_attach_calendar(runner):
'BEGIN:VCALENDAR\nBEGIN:VTODO\nEND:VTODO\nEND:VCALENDAR\n'
])
def test_no_vevent(runner, tmpdir, contents):
runner = runner(default_command='list', days=2)
runner = runner(days=2)
broken_item = runner.calendars['one'].join('broken_item.ics')
broken_item.write(contents.encode('utf-8'), mode='wb')

result = runner.invoke(main_khal)
result = runner.invoke(main_khal, ['list'])
assert not result.exception
assert 'No events' in result.output


def test_printformats(runner):
runner = runner(default_command='printformats', days=2)
runner = runner(days=2)

result = runner.invoke(main_khal)
result = runner.invoke(main_khal, ['printformats'])
assert '\n'.join(['longdatetimeformat: 21.12.2013 10:09',
'datetimeformat: 21.12. 10:09',
'longdateformat: 21.12.2013',
Expand All @@ -374,7 +361,7 @@ def test_printformats(runner):


def test_repeating(runner):
runner = runner(default_command='list', days=2)
runner = runner(days=2)
now = datetime.datetime.now().strftime('%d.%m.%Y')
end_date = datetime.datetime.now() + datetime.timedelta(days=10)
result = runner.invoke(
Expand All @@ -385,7 +372,7 @@ def test_repeating(runner):


def test_at(runner):
runner = runner(default_command='calendar', days=2)
runner = runner(days=2)
now = datetime.datetime.now().strftime('%d.%m.%Y')
end_date = datetime.datetime.now() + datetime.timedelta(days=10)
result = runner.invoke(
Expand All @@ -398,7 +385,7 @@ def test_at(runner):


def test_at_day_format(runner):
runner = runner(default_command='calendar', days=2)
runner = runner(days=2)
now = datetime.datetime.now().strftime('%d.%m.%Y')
end_date = datetime.datetime.now() + datetime.timedelta(days=10)
result = runner.invoke(
Expand All @@ -411,7 +398,7 @@ def test_at_day_format(runner):


def test_list(runner):
runner = runner(default_command='calendar', days=2)
runner = runner(days=2)
now = datetime.datetime.now().strftime('%d.%m.%Y')
end_date = datetime.datetime.now() + datetime.timedelta(days=10)
result = runner.invoke(
Expand All @@ -426,7 +413,7 @@ def test_list(runner):


def test_search(runner):
runner = runner(default_command='calendar', days=2)
runner = runner(days=2)
now = datetime.datetime.now().strftime('%d.%m.%Y')
result = runner.invoke(main_khal, 'new {} 18:00 myevent'.format(now).split())
format = '{red}{start-end-time-style}{reset} {title} :: {description}'
Expand Down Expand Up @@ -508,7 +495,7 @@ def test_import_from_stdin(runner):


def test_interactive_command(runner, monkeypatch):
runner = runner(default_command='list', days=2)
runner = runner(days=2)
token = "hooray"

def fake_ui(*a, **kw):
Expand All @@ -527,12 +514,12 @@ def fake_ui(*a, **kw):


def test_color_option(runner):
runner = runner(default_command='list', days=2)
runner = runner(days=2)

result = runner.invoke(main_khal, ['--no-color'])
result = runner.invoke(main_khal, ['--no-color', 'list'])
assert result.output == 'No events\n'

result = runner.invoke(main_khal, ['--color'])
result = runner.invoke(main_khal, ['--color', 'list'])
assert 'No events' in result.output
assert result.output != 'No events\n'

Expand Down Expand Up @@ -643,9 +630,9 @@ def test_configure_command(runner):


def test_print_ics_command(runner):
runner = runner(command='printics', days=2)
runner = runner()
# Input is empty and loading from stdin
result = runner.invoke(main_khal, ['-'])
result = runner.invoke(main_khal, ['printics', '-'])
assert result.exception

# Non existing file
Expand Down
3 changes: 0 additions & 3 deletions tests/settings_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ def test_simple_config(self):
'sqlite': {'path': os.path.expanduser('~/.local/share/khal/khal.db')},
'locale': LOCALE_BERLIN,
'default': {
'default_command': 'calendar',
'default_calendar': None,
'print_new': 'False',
'highlight_event_days': False,
Expand Down Expand Up @@ -77,7 +76,6 @@ def test_small(self):
},
'default': {
'default_calendar': None,
'default_command': 'calendar',
'print_new': 'False',
'highlight_event_days': False,
'timedelta': dt.timedelta(days=2),
Expand All @@ -99,7 +97,6 @@ def test_old_config(self, tmpdir):
dateformat: %d.%m.
longdateformat: %d.%m.%Y
[default]
default_command: calendar
"""
conf_path = str(tmpdir.join('old.conf'))
with open(conf_path, 'w+') as conf:
Expand Down

0 comments on commit f8d9135

Please sign in to comment.