-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Breaking change: Add 'list' command to show known databases, rearrang…
…e command line options, give better error on unknown db (#18) * Add list option * Rearrange command line arguments
- Loading branch information
1 parent
b8f9ef1
commit 5275292
Showing
14 changed files
with
169 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from .config import load_config | ||
|
||
|
||
def format_db_description(db_name, db_description): | ||
if db_description is not None: | ||
return f"{db_name} ({db_description})" | ||
else: | ||
return db_name | ||
|
||
|
||
def list_db_names() -> None: | ||
dbcli_config = load_config() | ||
|
||
dbs = dbcli_config.get('dbs', {}) | ||
db_descriptions = { | ||
db_name: db_config.get('description', None) | ||
for db_name, db_config | ||
in dbs.items() | ||
} | ||
|
||
output = [ | ||
format_db_description(db_name, db_description) | ||
for db_name, db_description | ||
in db_descriptions.items() | ||
] | ||
sorted_output = sorted(list(output)) | ||
print("Available db_names:") | ||
print("* ", end='') | ||
print("\n* ".join(sorted_output)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import subprocess | ||
|
||
|
||
def backtick(cmd): | ||
def backtick(cmd: str) -> str: | ||
return subprocess.check_output(cmd).decode('utf-8').strip() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
93.3100 | ||
97.9100 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
47.9200 | ||
72.6500 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
[coverage:report] | ||
exclude_lines = | ||
if TYPE_CHECKING: | ||
|
||
[pep8] | ||
max_line_length=100 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
from db_facts.runner import Runner | ||
import unittest | ||
from io import StringIO | ||
from unittest.mock import patch | ||
|
||
|
||
@patch('sys.stderr', new_callable=StringIO) | ||
@patch('sys.stdout', new_callable=StringIO) | ||
class TestRunnerList(unittest.TestCase): | ||
|
||
@patch('db_facts.list_db_names.load_config') | ||
def test_runner_list(self, | ||
mock_load_config, | ||
mock_stdout, | ||
mock_stderr): | ||
runner = Runner() | ||
mock_load_config.return_value = { | ||
'dbs': { | ||
'mydb1': { | ||
'description': 'My favorite database', | ||
'password': 'password', | ||
'host': 'host', | ||
'user': 'user', | ||
'type': 'type', | ||
'protocol': 'protocol', | ||
'port': 123, | ||
'database': 'dbname', | ||
'lastpass_share_name_suffix': 'lastpass_share_name_suffix', | ||
'connection_type': 'connection_type', | ||
}, | ||
'mydb2': { | ||
'password': 'password', | ||
'host': 'host', | ||
'user': 'user', | ||
'type': 'type', | ||
'protocol': 'protocol', | ||
'port': 123, | ||
'database': 'dbname', | ||
'lastpass_share_name_suffix': 'lastpass_share_name_suffix', | ||
'connection_type': 'connection_type', | ||
} | ||
} | ||
} | ||
|
||
self.assertEqual(0, runner.run(['/bin/db-facts', 'list'])) | ||
mock_load_config.assert_called_with() | ||
self.assertEqual(mock_stderr.getvalue(), '') | ||
self.assertEqual(mock_stdout.getvalue(), | ||
("Available db_names:\n" | ||
"* mydb1 (My favorite database)\n" | ||
"* mydb2\n")) |