Exemplo n.º 1
0
def main(command_executor: InteractiveCommandExecutor) -> None:
    """Entry point for this executable python module."""
    args = handle_args.setup_args_for_update()
    store_file_path = command_store.get_file_path(args.save_dir)
    store = command_store.load_command_store(store_file_path)
    print('Looking for all past commands with: ' + ", ".join(args.query))
    start_time = time.time()
    search_results = store.search_commands(
        args.query,
        args.startswith,
    )
    end_time = time.time()
    print(f"Search time: {end_time - start_time} seconds")
    print(f"Number of results found: {str(len(search_results))}")
    if len(search_results) > args.max:
        print(f"Results truncated to the first: {args.max}")
    search_results = search_results[:args.max]
    if len(search_results) > 0:
        if args.delete:
            print("Delete mode")
            command_store.print_commands(search_results, args.query)
            command_executor.delete_interaction(store, search_results)
        if args.updateinfo:
            print("Updating Info mode")
            command_executor.command_info_interaction(search_results, store)
def main(command_executor):
    """Entry point for this executable python module."""
    args = handle_args.setup_args_for_update()
    store_file_path = command_store.get_file_path(args.save_dir, args.json,
                                                  args.sql)
    store_type = command_store.get_store_type(args.json, args.sql)
    store = command_store.load_command_store(store_file_path, store_type)
    print('Looking for all past commands with: ' + ", ".join(args.query))
    result = store.search_commands(
        args.query,
        args.startswith,
    )
    print("Number of results found: " + str(len(result)))
    store_updated = False
    if args.delete and len(result) > 0:
        print("Delete mode")
        command_store.print_commands(result, args.query)
        store_updated = store_updated or command_executor.delete_interaction(
            store, result)
    if args.updateinfo and len(result) > 0:
        print("Updating Info mode")
        store_updated = store_updated or command_executor.set_command_info(
            result)
    if store_updated:
        print("Updating Command Store...")
        command_store.save_command_store(store, store_file_path, args.json)
 def test_print_commands_whenSingleCommand_shouldPrint(self) -> None:
     command_str = 'git diff HEAD^ src/b/FragmentOnlyDetector.java'
     command = command_store_lib.Command(command_str, 1234.1234)
     command_list = [command]
     with patch('sys.stdout', new_callable=io.StringIO) as std_out_mock:
         command_store_lib.print_commands(command_list)
         expected = command_store_lib._create_indexed_highlighted_print_string(
             1, command_str, command) + '\n'
         self.assertEqual(expected, std_out_mock.getvalue())
 def test_print_commands_whenSingleCommandWithHighlights_shouldPrintWithHighlights(self) -> None:
     command_str = 'git diff'
     command = command_store_lib.Command(command_str, 1234.1234)
     command_list = [command]
     with patch('sys.stdout', new_callable=io.StringIO) as std_out_mock:
         command_store_lib.print_commands(command_list, ['git'])
         expected = command_store_lib._create_indexed_highlighted_print_string(
             1, command_str, command) + '\n'
         expected = command_store_lib._highlight_term_in_string(expected, 'git')
         self.assertEqual(expected, std_out_mock.getvalue())
Exemplo n.º 5
0
def display_and_interact_results(result: List[Command],
                                 max_return_count: int,
                                 save_dir: str,
                                 history_file_path: str,
                                 query: Optional[List[str]],
                                 execute: bool) -> Optional[str]:
    print(f"Number of results found: {str(len(result))}")
    if len(result) > max_return_count:
        print(f"Results truncated to the first: {max_return_count}")
        result = result[:max_return_count]
    last_saved_file_path = os.path.join(save_dir, command_store.DEFAULT_LAST_SAVE_FILE_NAME)
    command_store.save_last_search(last_saved_file_path, result)
    if execute:
        command_executor = load_user_interactor(history_file_path)
        if not command_executor.run(result):
            return 'Exit'
    command_store.print_commands(result, query)
    return None