Skip to content

Commit

Permalink
WIP - split migrate command into two
Browse files Browse the repository at this point in the history
  • Loading branch information
Arxcis committed Jul 19, 2019
1 parent ce894db commit a6107f4
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 40 deletions.
2 changes: 1 addition & 1 deletion goto/commands/migrate.py
Expand Up @@ -8,7 +8,7 @@
from .. import settings


def migrate(magic, command, args):
def migrate(magic, command, args, options):
"""
migrate magicwords.
"""
Expand Down
9 changes: 9 additions & 0 deletions goto/commands/migrate_check.py
@@ -0,0 +1,9 @@



def migrate_check(magic, command, args, options):

if not detect_unmigrated_data():
return "Nothing to migrate", None
elif '--check-migrate' in command:
return None, GotoWarning('data_not_migrated')
2 changes: 1 addition & 1 deletion goto/commands/rename.py
Expand Up @@ -14,7 +14,7 @@ def rename(magic, command, args, options):
command=command, magicword=from_magicword)

to_magicword = args[1]
overwrite = '-f' in args or '--force' in args
overwrite = '-f' in options or '--force' in options

err = magic.rename_shortcut(from_magicword, to_magicword, overwrite)
if err:
Expand Down
57 changes: 27 additions & 30 deletions goto/the_real_goto.py
Expand Up @@ -16,34 +16,32 @@
from . import commands


input_commands = {
'--help': 'usage',
'-h': 'usage',
'help': 'usage',
'/?': 'usage',

'add': 'add',
'update': 'update',
'rm': 'rm',
'show': 'show',
'copy': 'copy',
'list': 'list',
'mv': 'rename',
'rename': 'rename',

'--migrate': 'migrate',
'--check-migrate': 'migrate',

'subl': 'subl',
'vscode': 'vscode',
'intelij': 'intelij',
'idea': 'intelij'
command_map = {
'--help': commands.usage,
'-h': commands.usage,
'help': commands.usage,
'/?': commands.usage,

'add': commands.add,
'update': commands.update,
'rm': commands.rm,
'show': commands.show,
'copy': commands.copy,
'list': commands.list,
'mv': commands.rename,
'rename': commands.rename,

'--migrate': commands.migrate,
'--check-migrate': commands.migrate,

'subl': commands.subl,
'vscode': commands.vscode,
'intelij': commands.intellij,
'idea': commands.intellij,
}

commands = set(input_commands.values())


def main():

make_sure_we_print_in_utf8()

fix_python2()
Expand All @@ -59,7 +57,7 @@ def main():
options = list(filter(lambda word: word.startswith('-'), argv))

if not command and len(args) == 0:
output, _ = commands.usage()
output = commands.usage()
print_utf8(output)
exit(0)

Expand All @@ -78,7 +76,7 @@ def main():
def parse_command(argv):

for arg in argv:
if arg in commands.map.keys():
if arg in command_map.keys():
command = arg
argv.remove(arg)
return command, argv
Expand All @@ -88,7 +86,7 @@ def parse_command(argv):

def run_command(magic, command, args, options):
if command:
return commands.map[command](magic, command, args, options)
return command_map[command](magic, command, args, options)
else:
return commands.default(magic, None, args, options)

Expand All @@ -102,11 +100,10 @@ def exit_if_unhealthy():

def exit_with_usage_if_needed():
if len(sys.argv) < 3:
output, _ = commands.usage()
output = commands.usage()
print_utf8(output)
exit(0)

exit(0)

def make_sure_we_print_in_utf8():
try:
Expand Down
11 changes: 3 additions & 8 deletions test_end_to_end.sh
Expand Up @@ -33,7 +33,7 @@ function _fail_test {
message=$1
echo -e "${RED}Test failed - $message${NC}"
echo "LAST RUN CMD: $LATEST_RAN_COMMAND"
echo
echo
echo "OUTPUT: $(cat "$OUTPUTFILE")"
echo
_display_projectfile
Expand Down Expand Up @@ -409,14 +409,9 @@ function test_13_goto_rename_æøå {

echo ... Invoking rename targeting existing magicword and setting force flag to true
_cmd_should_succeed "goto rename $existing_magicword1 $existing_magicword2 --force"
<<<<<<< HEAD:goto/tests/test_end_to_end.sh

=======
_cmd_should_succeed "goto rename $existing_magicword2 $existing_magicword1 -f"
_cmd_should_succeed "goto rename $existing_magicword1 $existing_magicword2 --force"


>>>>>>> develop:test_end_to_end.sh
_projectfile_should_not_contain $existing_magicword1
_projectfile_should_contain $existing_magicword2
_projectfile_should_contain $new_magicword
Expand All @@ -434,7 +429,7 @@ function test_14_unmigrated_data_detection {
# goto should detect it and prompt the user to migrate data.
# But running a prompting command would hault the test run forever,
# so we give it some input.

# Simulating Ctrl+D by closing stdin: 0<&-
_cmd_should_fail 'goto'
_failing_cmd_should_give_human_message 'goto'
Expand Down Expand Up @@ -470,7 +465,7 @@ function test_15_migrate_data {
fi

jfiles=(`find "$GOTOPATH/projects" -maxdepth 1 -type f -name "*.json"`)
if [ ${#jfiles[@]} -ne 0 ]; then
if [ ${#jfiles[@]} -ne 0 ]; then
_fail_test "jfiles still present in project folder"
fi

Expand Down

0 comments on commit a6107f4

Please sign in to comment.