summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorTimothy Crosley <timothy.crosley@gmail.com>2013-10-07 18:51:24 -0400
committerTimothy Crosley <timothy.crosley@gmail.com>2013-10-07 18:51:24 -0400
commitc84b4910656663b4d16917738eba9befa10d3958 (patch)
treec1e23896f955d1a855c04b3c61c6213ccf0f31ef /scripts
parent84cbda270d9e3f6cb2331e80bdc948f7847bbe3a (diff)
downloadisort-c84b4910656663b4d16917738eba9befa10d3958.tar.gz
Fix issue 38: provide a simple flag for moving outputing to stdout (-d)
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/isort55
1 files changed, 27 insertions, 28 deletions
diff --git a/scripts/isort b/scripts/isort
index 21aac59e..1fa0c228 100755
--- a/scripts/isort
+++ b/scripts/isort
@@ -9,39 +9,38 @@ from pies import *
from isort import __version__, SortImports
-parser = argparse.ArgumentParser(description="Sort Python import definitions alphabetically within logical sections.")
-parser.add_argument("files", nargs="+", help="One or more Python source files that need their imports sorted.")
-parser.add_argument("-l", "--lines", help="The max length of an import line (used for wrapping long imports).",
- dest="line_length", type=int)
-parser.add_argument("-s", "--skip", help="Files that sort imports should skip over.", dest="skip", action="append")
-parser.add_argument("-t", "--top", help="Force specific imports to the top of their appropriate section.",
- dest="force_to_top", action="append")
-parser.add_argument("-b", "--builtin", dest="known_standard_library", action="append",
- help="Force sortImports to recognize a module as part of the python standard library.")
-parser.add_argument("-o", "--thirdparty", dest="known_third_party", action="append",
- help="Force sortImports to recognize a module as being part of a third party library.")
-parser.add_argument("-p", "--project", dest="known_first_party", action="append",
- help="Force sortImports to recognize a module as being part of the current python project.")
-parser.add_argument("-m", "--multi_line", help="Multi line output (0-grid, 1-vertical, 2-hanging, 3-vert-hanging).",
- dest="multi_line_output", type=int, choices=[0, 1, 2, 3])
-parser.add_argument("-i", "--indent", help="String to place for indents defaults to ' ' (4 spaces).",
- dest="indent", type=str)
-parser.add_argument("-a", "--add_import", dest="add_imports", action="append",
- help="Adds the specified import line to all files, automatically determining correct placement.")
-parser.add_argument("-r", "--remove_import", dest="remove_imports", action="append",
- help="Removes the specified import from all files.")
-parser.add_argument("-ls", "--length_sort", help="Sort imports by their string length.",
- dest="length_sort", action="store_true", default=False)
-parser.add_argument('--version', action='version', version='isort {0}'.format(__version__))
+parser = argparse.ArgumentParser(description='Sort Python import definitions alphabetically within logical sections.')
+parser.add_argument('files', nargs='+', help='One or more Python source files that need their imports sorted.')
+parser.add_argument('-l', '--lines', help='The max length of an import line (used for wrapping long imports).',
+ dest='line_length', type=int)
+parser.add_argument('-s', '--skip', help='Files that sort imports should skip over.', dest='skip', action='append')
+parser.add_argument('-t', '--top', help='Force specific imports to the top of their appropriate section.',
+ dest='force_to_top', action='append')
+parser.add_argument('-b', '--builtin', dest='known_standard_library', action='append',
+ help='Force sortImports to recognize a module as part of the python standard library.')
+parser.add_argument('-o', '--thirdparty', dest='known_third_party', action='append',
+ help='Force sortImports to recognize a module as being part of a third party library.')
+parser.add_argument('-p', '--project', dest='known_first_party', action='append',
+ help='Force sortImports to recognize a module as being part of the current python project.')
+parser.add_argument('-m', '--multi_line', help='Multi line output (0-grid, 1-vertical, 2-hanging, 3-vert-hanging).',
+ dest='multi_line_output', type=int, choices=[0, 1, 2, 3])
+parser.add_argument('-i', '--indent', help='String to place for indents defaults to ' ' (4 spaces).',
+ dest='indent', type=str)
+parser.add_argument('-a', '--add_import', dest='add_imports', action='append',
+ help='Adds the specified import line to all files, automatically determining correct placement.')
+parser.add_argument('-r', '--remove_import', dest='remove_imports', action='append',
+ help='Removes the specified import from all files.')
+parser.add_argument('-ls', '--length_sort', help='Sort imports by their string length.',
+ dest='length_sort', action='store_true', default=False)
+parser.add_argument('-d', '--stdout', help='Force resulting output to stdout, instead of in-place.',
+ dest='write_to_stdout', action='store_true')
+parser.add_argument('-v', '--version', action='version', version='isort {0}'.format(__version__))
arguments = dict((key, value) for (key, value) in iteritems(vars(parser.parse_args())) if value)
file_names = arguments.pop('files', [])
if file_names == ['-']:
- import sys
- sorted_file = SortImports(file_contents=sys.stdin.read(), **arguments)
- sys.stdout.write(sorted_file.output)
-
+ SortImports(file_contents=sys.stdin.read(), write_to_stdout=True, **arguments)
else:
for file_name in file_names:
SortImports(file_name, **arguments)