diff mercurial-common/src/python/load-commands-command.py @ 828:8d02c7b1f812

use HG extension to pass infinite commandline arguments list
author eugene.petrenko@jetbrains.com
date Fri, 30 May 2014 17:29:51 +0200
parents
children ef19cc8d5bc1
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mercurial-common/src/python/load-commands-command.py	Fri May 30 17:29:51 2014 +0200
@@ -0,0 +1,58 @@
+#!/usr/bin/env python
+##
+##    Copyright 2000-2014 JetBrains
+##
+##     Licensed under the Apache License, Version 2.0 (the "License");
+##       you may not use this file except in compliance with the License.
+##      You may obtain a copy of the License at
+##
+##          http://www.apache.org/licenses/LICENSE-2.0
+##
+##       Unless required by applicable law or agreed to in writing, software
+##       distributed under the License is distributed on an "AS IS" BASIS,
+##       WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+##       See the License for the specific language governing permissions and
+##       limitations under the License.
+##
+##
+##  http://www.gnu.org/licenses/gpl-faq.html#GPLModuleLicense
+##  http://www.gnu.org/licenses/license-list.html#apache2
+##  http://en.wikipedia.org/wiki/Apache_License#GPL_compatibility
+##
+##
+"""
+load-commands-command
+"""
+
+import codecs
+from mercurial import dispatch
+
+def loadArguments(ui, params_file):
+  file_commands = []
+  ui.write("Parameters from the file (one by line):\n")
+  with codecs.open(params_file, "r", "utf-8") as f:
+    for _line in f:
+      line = _line.strip()
+      if len(line) <= 0:
+        continue
+
+      ui.write("  " + line + "\n")
+      file_commands.append(line)
+  return file_commands
+
+
+def load_commands_command(ui, repo, params_file, *pats, **opts):
+  ui.write("Staring command with arguments from " + params_file + "\n")
+  command_arguments = loadArguments(ui, params_file)
+
+  ui.write("\nRunning the command...\n\n")
+  return dispatch.dispatch(dispatch.request(command_arguments))
+
+#so here goes command registration and options
+cmdtable = {
+    "CMD": (load_commands_command, [ ], "params_file [foo]...")
+}
+
+testedwith = '2.2.2'
+buglink = "@jonnyzzz"
+