Skip to content

Commit

Permalink
Added 'tags' argument to snapshot command (#157)
Browse files Browse the repository at this point in the history
Added functionality to specify restic's `--tag` argument when using the
`snapshots()` command. Added associated unit test.
  • Loading branch information
wigeon-aloft committed Feb 29, 2024
1 parent 5454222 commit c3068e4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/index.md
Expand Up @@ -475,6 +475,7 @@ Retrieve a list of snapshots in the repo

- `snapshot_id`: ID of the snapshot which should be listed
- `group_by`: String for grouping snapshots by host, paths, tags
- `tags`: List of snapshot tags

### Returns

Expand Down
5 changes: 4 additions & 1 deletion restic/internal/snapshots.py
Expand Up @@ -3,7 +3,7 @@
from restic.internal import command_executor


def run(restic_base_command, snapshot_id=None, group_by=None):
def run(restic_base_command, snapshot_id=None, group_by=None, tags=None):
cmd = restic_base_command + ['snapshots']

if snapshot_id:
Expand All @@ -12,4 +12,7 @@ def run(restic_base_command, snapshot_id=None, group_by=None):
if group_by:
cmd.extend(['--group-by', group_by])

if tags:
cmd.extend(['--tag', ','.join(tags)])

return json.loads(command_executor.execute(cmd))
9 changes: 9 additions & 0 deletions restic/internal/snapshots_test.py
Expand Up @@ -36,6 +36,15 @@ def test_snapshots_id(self, mock_execute):
mock_execute.assert_called_with(
['restic', '--json', 'snapshots', 'latest'])

@mock.patch.object(snapshots.command_executor, 'execute')
def test_snapshots_tags(self, mock_execute):
mock_execute.return_value = '[]'

self.assertEqual([], restic.snapshots(tags=['test', 'test2']))

mock_execute.assert_called_with(
['restic', '--json', 'snapshots', '--tag', 'test,test2'])

@mock.patch.object(snapshots.command_executor, 'execute')
def test_snapshots_parses_result_json(self, mock_execute):
mock_execute.return_value = """
Expand Down

0 comments on commit c3068e4

Please sign in to comment.