Skip to content

Commit cdfb298

Browse files
authored
Merge pull request #315 from softwarepub/feature/280-version-cmd
Add version subcommand
2 parents fd88160 + a20c219 commit cdfb298

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

src/hermes/commands/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
# flake8: noqa
1010

1111
from hermes.commands.base import HermesHelpCommand
12+
from hermes.commands.base import HermesVersionCommand
1213
from hermes.commands.clean.base import HermesCleanCommand
1314
from hermes.commands.init.base import HermesInitCommand
1415
from hermes.commands.curate.base import HermesCurateCommand

src/hermes/commands/base.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,3 +206,23 @@ def __call__(self, args: argparse.Namespace) -> None:
206206
def load_settings(self, args: argparse.Namespace):
207207
"""No settings are needed for the help command."""
208208
pass
209+
210+
211+
class HermesVersionSettings(BaseModel):
212+
"""Intentionally empty settings class for the version command."""
213+
pass
214+
215+
216+
class HermesVersionCommand(HermesCommand):
217+
"""Show HERMES version and exit."""
218+
219+
command_name = "version"
220+
settings_class = HermesVersionSettings
221+
222+
def load_settings(self, args: argparse.Namespace):
223+
"""Pass loading settings as not necessary for this command."""
224+
pass
225+
226+
def __call__(self, args: argparse.Namespace) -> None:
227+
self.log.info(metadata.version("hermes"))
228+
self.parser.exit()

src/hermes/commands/cli.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
import sys
1313

1414
from hermes import logger
15-
from hermes.commands import HermesHelpCommand, HermesCleanCommand, HermesHarvestCommand, HermesProcessCommand, \
16-
HermesCurateCommand, HermesDepositCommand, HermesPostprocessCommand, HermesInitCommand
15+
from hermes.commands import (HermesHelpCommand, HermesVersionCommand, HermesCleanCommand,
16+
HermesHarvestCommand, HermesProcessCommand, HermesCurateCommand,
17+
HermesDepositCommand, HermesPostprocessCommand, HermesInitCommand)
1718
from hermes.commands.base import HermesCommand
1819

1920

@@ -36,6 +37,7 @@ def main() -> None:
3637

3738
for command in (
3839
HermesHelpCommand(parser),
40+
HermesVersionCommand(parser),
3941
HermesInitCommand(parser),
4042
HermesCleanCommand(parser),
4143
HermesHarvestCommand(parser),

0 commit comments

Comments
 (0)