Commit 0e51da51 authored by Kees Hink's avatar Kees Hink Committed by Brian May

Allow comments in configuration file

parent a22c453d
...@@ -305,6 +305,17 @@ Arguments read from a file must be one per line, as shown below:: ...@@ -305,6 +305,17 @@ Arguments read from a file must be one per line, as shown below::
--option2 --option2
value2 value2
Comments in config file
.......................
It's possible to add comments in the configuration file. This allows annotating the
various subnets with human-readable descriptions, like::
# company-internal API
8.8.8.8/32
# home IoT
192.168.63.0/24
Examples Examples
-------- --------
......
...@@ -152,6 +152,10 @@ class Concat(Action): ...@@ -152,6 +152,10 @@ class Concat(Action):
# beginning/end of the lines. # beginning/end of the lines.
class MyArgumentParser(ArgumentParser): class MyArgumentParser(ArgumentParser):
def convert_arg_line_to_args(self, arg_line): def convert_arg_line_to_args(self, arg_line):
# Ignore comments
if arg_line.startswith("#"):
return []
# strip whitespace at beginning and end of line # strip whitespace at beginning and end of line
arg_line = arg_line.strip() arg_line = arg_line.strip()
......
...@@ -100,3 +100,8 @@ def test_parse_subnetport_ip6_with_mask_and_port(): ...@@ -100,3 +100,8 @@ def test_parse_subnetport_ip6_with_mask_and_port():
== [(socket.AF_INET6, ip, 128, 80, 80)] == [(socket.AF_INET6, ip, 128, 80, 80)]
assert sshuttle.options.parse_subnetport('[' + ip_repr + '/16]:80-90')\ assert sshuttle.options.parse_subnetport('[' + ip_repr + '/16]:80-90')\
== [(socket.AF_INET6, ip, 16, 80, 90)] == [(socket.AF_INET6, ip, 16, 80, 90)]
def test_convert_arg_line_to_args_skips_comments():
parser = sshuttle.options.MyArgumentParser()
assert parser.convert_arg_line_to_args("# whatever something") == []
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment