Skip to content

Commit

Permalink
Minor bug fixes & cleanups
Browse files Browse the repository at this point in the history
- Fixed bug in interactive 'promote' (unfortunately, not easily covered by
  unit tests due to the interactive nature of the process.)
- Fixed up a direct call to sys.exit(); instead of a return.
- Fixed typos in comments
- Fixed super old 'splconf' references and updated to 'ksconf'
  • Loading branch information
lowell80 committed Jun 28, 2018
1 parent 6d94ef9 commit 53f61dd
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
20 changes: 10 additions & 10 deletions ksconf/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def cli(argv=None, _unittest=False):

subparsers = parser.add_subparsers()

# SUBCOMMAND: splconf check <CONF>
# SUBCOMMAND: ksconf check <CONF>
sp_chck = subparsers.add_parser("check",
help="Perform basic syntax and sanity checks on .conf files",
description=
Expand All @@ -136,9 +136,9 @@ def cli(argv=None, _unittest=False):
help="Abort check if more than this many files fail validation. Useful
for a pre-commit hook where any failure is unacceptable.")
'''
# Usage example: find . -name '*.conf' | splconf check - (Nice little pre-commit script)
# Usage example: find . -name '*.conf' | ksconf check - (Nice little pre-commit script)

# SUBCOMMAND: splconf combine --target=<DIR> <SRC1> [ <SRC-n> ]
# SUBCOMMAND: ksconf combine --target=<DIR> <SRC1> [ <SRC-n> ]
sp_comb = subparsers.add_parser("combine",
help=
"Merge configuration files from one or more source directories "
Expand Down Expand Up @@ -266,7 +266,7 @@ def cli(argv=None, _unittest=False):
"edit hand-edit this file! ****",
help="A warning banner telling discouraging editing of conf files.")

# SUBCOMMAND: splconf diff <CONF> <CONF>
# SUBCOMMAND: ksconf diff <CONF> <CONF>
sp_diff = subparsers.add_parser("diff",
help="Compares settings differences of two .conf files "
"ignoring textual and sorting differences",
Expand Down Expand Up @@ -294,7 +294,7 @@ def cli(argv=None, _unittest=False):
action="store_true", default=False,
help="Enable comparison of comments. (Unlikely to work consistently)")

# SUBCOMMAND: splconf promote --target=<CONF> <CONF>
# SUBCOMMAND: ksconf promote --target=<CONF> <CONF>
sp_prmt = subparsers.add_parser("promote",
help="Promote .conf settings from one file into another either "
"in batch mode (all changes) or interactively allowing "
Expand Down Expand Up @@ -400,7 +400,7 @@ def cli(argv=None, _unittest=False):
"""

# SUBCOMMAND: splconf merge --target=<CONF> <CONF> [ <CONF-n> ... ]
# SUBCOMMAND: ksconf merge --target=<CONF> <CONF> [ <CONF-n> ... ]
sp_merg = subparsers.add_parser("merge",
help="Merge two or more .conf files",
formatter_class=MyDescriptionHelpFormatter)
Expand All @@ -423,11 +423,11 @@ def cli(argv=None, _unittest=False):
help="A banner or warning comment to add to the TARGET file. Often used "
"to warn Splunk admins from editing a auto-generated file.")

# SUBCOMMAND: splconf minimize --target=<CONF> <CONF> [ <CONF-n> ... ]
# SUBCOMMAND: ksconf minimize --target=<CONF> <CONF> [ <CONF-n> ... ]
# Example workflow:
# 1. cp default/props.conf local/props.conf
# 2. vi local/props.conf (edit JUST the lines you want to change)
# 3. splconf minimize --target=local/props.conf default/props.conf
# 3. ksconf minimize --target=local/props.conf default/props.conf
# (You could take this a step further by appending "$SPLUNK_HOME/system/default/props.conf"
# and removing any SHOULD_LINEMERGE = true entries (for example)
sp_minz = subparsers.add_parser("minimize",
Expand Down Expand Up @@ -512,7 +512,7 @@ def cli(argv=None, _unittest=False):
"often desirable keep the 'disabled' settings in the local file, "
"even if it's enabled by default.")

# SUBCOMMAND: splconf sort <CONF>
# SUBCOMMAND: ksconf sort <CONF>
sp_sort = subparsers.add_parser("sort",
help="Sort a Splunk .conf file. Sorted output can be echoed "
"or files can be sorted inplace.",
Expand Down Expand Up @@ -555,7 +555,7 @@ def cli(argv=None, _unittest=False):
sp_sort.add_argument("-n", "--newlines", metavar="LINES", type=int, default=1,
help="Lines between stanzas.")

# SUBCOMMAND: splconf upgrade tarball
# SUBCOMMAND: ksconf upgrade tarball
sp_unar = subparsers.add_parser("unarchive",
help="Install or overwrite an existing app in a git-friendly "
"way. If the app already exist, steps will be taken to "
Expand Down
2 changes: 1 addition & 1 deletion ksconf/commands/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ def do_check(args):
sys.stdout.write("Completed checking {0[checked]} files. rc={1} Breakdown:\n"
" {0[okay]} files were parsed successfully.\n"
" {0[error]} files failed.\n".format(c, exit_code))
sys.exit(exit_code)
return exit_code
2 changes: 1 addition & 1 deletion ksconf/commands/promote.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def do_promote(args):

while True:
resp = input("Would you like to apply ALL changes? (y/n/d/q)")
resp = input[:1].lower()
resp = resp[:1].lower()
if resp == 'q':
return EXIT_CODE_USER_QUIT
elif resp == 'd':
Expand Down
6 changes: 3 additions & 3 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ def test_diff_stdin(self):
'''

def test_diff_multiline(self):
""" Force the generate of a multi-line value diff """
""" Force the generation of a multi-line value diff """
twd = TestWorkDir()
conf1 = twd.write_file("savedsearches-1.conf", r"""
[indexed_event_counts_hourly]
Expand Down Expand Up @@ -520,7 +520,7 @@ def test_mixed(self):
self.assertEqual(ko.returncode, EXIT_CODE_BAD_CONF_FILE)

def test_mixed_stdin(self):
""" Make sure that if even a single file files, the exit code should be "BAD CONF" """
""" Make sure that if even a single file fails the exit code should be "BAD CONF" """
try:
_stdin = sys.stdin
sys.stdin = StringIO("\n".join([self.conf_good, self.conf_bad]))
Expand All @@ -531,7 +531,7 @@ def test_mixed_stdin(self):
sys.stdin = _stdin

def test_mixed_quiet(self):
""" Make sure that if even a single file files, the exit code should be "BAD CONF" """
""" Make sure that if even a single file fails the exit code should be "BAD CONF" """
with ksconf_cli:
ko = ksconf_cli("check", self.conf_good, self.conf_bad)
self.assertEqual(ko.returncode, EXIT_CODE_BAD_CONF_FILE)
Expand Down

0 comments on commit 53f61dd

Please sign in to comment.