Skip to content

Commit

Permalink
Avoid crash when using plugin without cli_options attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
pylipp committed Dec 16, 2021
1 parent e5f486b commit 746df3b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
4 changes: 4 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Fixed
### Removed

## [v0.26.2.1] - 2021-12-16
### Fixed
- Avoid crash in `cli._parse_command()` when using plugin without `cli_options` attribute.

## [v0.26.2.0] - 2021-12-12
### Added
- Support extending `fina` CLI in plugins by providing a `plugin.PluginCliOptions` utility class.
Expand Down
7 changes: 6 additions & 1 deletion financeager/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,18 @@ def extend(self, command_parser):
"""


class DefaultPluginCliOptions(PluginCliOptions):
def extend(self, _):
pass


class PluginBase:
def __init__(self, *, name, config, cli_options=None):
"""Set plugin name, config (a PluginConfiguration instance), and optional CLI
options (a PluginCliOptions instance)."""
self.name = name
self.config = config
self.cli_options = cli_options
self.cli_options = cli_options or DefaultPluginCliOptions()


class ServicePlugin(PluginBase):
Expand Down
7 changes: 6 additions & 1 deletion test/test_clients.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import unittest

from financeager import clients, config, plugin
from financeager import cli, clients, config, plugin

from . import test_config

Expand Down Expand Up @@ -34,6 +34,11 @@ def test_create(self):
self.assertIsNone(client.sinks)
self.assertIsInstance(client, TestClient)

# And running the CLI parser does not error
self.assertEqual(
cli._parse_command(["list"], plugins=[some_plugin])["command"],
"list")


if __name__ == "__main__":
unittest.main()

0 comments on commit 746df3b

Please sign in to comment.