Skip to content

[21698] Add -v or --version to cli command tool #5401

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,8 @@ if(INSTALL_TOOLS)
)
endif()

install(FILES "${CMAKE_SOURCE_DIR}/package.xml" DESTINATION "${CMAKE_INSTALL_PREFIX}")

if(BUILD_DOCUMENTATION)

# Instalation of doxygen files
Expand Down
16 changes: 15 additions & 1 deletion tools/fastdds/fastdds.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@
"""

import argparse
import pathlib
import sys
import textwrap
import xml.etree.ElementTree as ET

from discovery.parser import Parser as DiscoveryParser

Expand Down Expand Up @@ -78,6 +81,7 @@ def __init__(self):
parser.add_argument('command',
nargs='?',
help='Command to run')
parser.add_argument('-v', '--version', action='store_true', help='Print Fast DDS version')

args = parser.parse_args(sys.argv[1:2])

Expand All @@ -86,6 +90,17 @@ def __init__(self):
print('Invalid command')
else:
getattr(self, args.command)()
elif args.version:
parents_path = list(pathlib.Path(__file__).parent.resolve().parents)
path_to_package_xml = [p for p in parents_path if p.name == 'fastdds'][0] / 'package.xml'
tree = ET.parse(path_to_package_xml)
root = tree.getroot()
name = 'Fast DDS'
version = root.find('version').text
description = root.find('description').text.replace('*', '')
print(f"\n\033[1m{name} version: {version}\033[0m\n")
print("\033[1mDescription:\033[0m\n")
print(textwrap.fill(description, width=120, subsequent_indent=" ") + "\n")
else:
parser.print_help()

Expand Down Expand Up @@ -122,7 +137,6 @@ def xml(self):
except ImportError:
sys.exit(1)


if __name__ == '__main__':

FastDDSParser()
Loading