diff --git a/gcalcli/argparsers.py b/gcalcli/argparsers.py index 93fab5d..5cd6483 100644 --- a/gcalcli/argparsers.py +++ b/gcalcli/argparsers.py @@ -17,6 +17,19 @@ from .details import DETAILS from .printer import valid_color_name + +def shorten_path(path: pathlib.Path) -> pathlib.Path: + """Try to shorten path using special characters like ~. + + Returns original path unmodified if it can't be shortened. + """ + tilde_home = pathlib.Path('~') + expanduser_len = len(tilde_home.expanduser().parts) + if path.parts[:expanduser_len] == tilde_home.expanduser().parts: + return tilde_home.joinpath(*path.parts[expanduser_len:]) + return path + + PROGRAM_OPTIONS = { '--client-id': {'default': None, 'type': str, 'help': 'API client_id'}, '--client-secret': { @@ -33,7 +46,7 @@ 'is no longer supported.', }, '--config-folder': { - 'default': env.default_config_dir(), + 'default': shorten_path(env.default_config_dir()), 'type': pathlib.Path, 'help': 'Optional directory used to load config files. Deprecated: ' 'prefer $GCALCLI_CONFIG.', @@ -314,18 +327,6 @@ class RawDescArgDefaultsHelpFormatter( """ -def shorten_path(path: pathlib.Path) -> pathlib.Path: - """Try to shorten path using special characters like ~. - - Returns original path unmodified if it can't be shortened. - """ - tilde_home = pathlib.Path('~') - expanduser_len = len(tilde_home.expanduser().parts) - if path.parts[:expanduser_len] == tilde_home.expanduser().parts: - return tilde_home.joinpath(*path.parts[expanduser_len:]) - return path - - @parser_allow_deprecated(name='program') def get_argument_parser(): config_dir = shorten_path(env.default_config_dir()) diff --git a/tests/cli/test.bats b/tests/cli/test.bats index 416f323..d5fa32d 100644 --- a/tests/cli/test.bats +++ b/tests/cli/test.bats @@ -1,10 +1,18 @@ setup() { load 'test_helper/bats-support/load' load 'test_helper/bats-assert/load' + load 'test_helper/bats-file/load' load 'test_helper/bats-snapshot/load' + + TEST_HOME_DIR="$(temp_make)" + export HOME="$TEST_HOME_DIR" export GCALCLI_USERLESS_MODE=1 } +function teardown() { + temp_del "$TEST_HOME_DIR" +} + @test "can run" { run gcalcli assert_equal $status 2