Skip to content

Commit

Permalink
Fix command line arg parsing from string (#132)
Browse files Browse the repository at this point in the history
  • Loading branch information
soininen authored Mar 1, 2024
2 parents cd1e475 + ea4c030 commit 47ced11
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
8 changes: 2 additions & 6 deletions spine_engine/utils/command_line_arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@
# Public License for more details. You should have received a copy of the GNU Lesser General Public License along with
# this program. If not, see <http://www.gnu.org/licenses/>.
######################################################################################################################

"""
Split command line arguments.
"""
""" Split command line arguments. """


def split_cmdline_args(arg_string):
Expand All @@ -40,7 +36,7 @@ def split_cmdline_args(arg_string):
quoted_context = False
elif not character.isspace() or quoted_context:
current_word = current_word + character
else:
elif current_word:
tokens.append(current_word)
current_word = ""
if current_word:
Expand Down
9 changes: 5 additions & 4 deletions tests/utils/test_command_line_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@
# this program. If not, see <http://www.gnu.org/licenses/>.
######################################################################################################################

"""
Unit tests for command line args module.
"""
""" Unit tests for command line args module. """

import unittest
from spine_engine.utils.command_line_arguments import split_cmdline_args
Expand All @@ -33,6 +30,10 @@ def test_split_cmdline_args(self):
self.assertEqual(splitted, ["--file=file name with spaces.dat", "-i", "3"])
splitted = split_cmdline_args("'quotation \"within\" a quotation'")
self.assertEqual(splitted, ['quotation "within" a quotation'])
splitted = split_cmdline_args(" ")
self.assertEqual(splitted, [])
splitted = split_cmdline_args("-a -b")
self.assertEqual(splitted, ["-a", "-b"])


if __name__ == "__main__":
Expand Down

0 comments on commit 47ced11

Please sign in to comment.