parser = argparse.ArgumentParser(
description='Copy data from the local filesystem to Keep.')
-parser.add_argument('paths', metavar='path', type=str, nargs='+',
- help='Local file or directory.')
+parser.add_argument('paths', metavar='path', type=str, nargs='*',
+ help="""
+Local file or directory. Default: read from standard input.
+""")
parser.add_argument('--max-manifest-depth', type=int, metavar='N', default=-1,
help="""
Maximum depth of directory tree to represent in the manifest
a single stream. Default: -1 (unlimited), i.e., exactly one manifest
stream per filesystem directory that contains files.
""")
-parser.add_argument('--as-stream', action='store_true',
- help="""
+group = parser.add_mutually_exclusive_group()
+group.add_argument('--as-stream', action='store_true', dest='stream',
+ help="""
+Synonym for --stream.
+""")
+group.add_argument('--stream', action='store_true',
+ help="""
Store the file content and display the resulting manifest on
stdout. Do not write the manifest to Keep or save a Collection object
in Arvados.
""")
-parser.add_argument('--as-manifest', action='store_const',
- dest='as_stream', const=False, default=False,
- help="""
+group.add_argument('--as-manifest', action='store_true', dest='manifest',
+ help="""
+Synonym for --manifest.
+""")
+group.add_argument('--manifest', action='store_true',
+ help="""
Store the file data and resulting manifest in Keep, save a Collection
object in Arvados, and display the manifest locator (Collection uuid)
on stdout. This is the default behavior.
""")
-parser.add_argument('--as-raw', action='store_true',
- help="""
+group.add_argument('--as-raw', action='store_true', dest='raw',
+ help="""
+Synonym for --raw.
+""")
+group.add_argument('--raw', action='store_true',
+ help="""
Store the file content and display the data block locators on stdout,
separated by spaces, with a trailing newline. Do not store a manifest.
""")
args = parser.parse_args()
+if len(args.paths) == 0:
+ args.paths += ['/dev/stdin']
+
if args.filename and (len(args.paths) != 1 or os.path.isdir(args.paths[0])):
parser.error("""
--filename argument cannot be used when storing a directory or
break
writer.write(buf)
-if args.as_stream:
+if args.stream:
print writer.manifest_text(),
-elif args.as_raw:
+elif args.raw:
writer.finish_current_stream()
print string.join(writer.data_locators(), ' ') + '\n'
else:
end
end
- def test_no_args
- out, err = capture_subprocess_io do
- assert_equal(false, arv_put,
- 'arv-put without args exits non-zero')
- end
- assert_equal '', out
- assert_match /^usage:/, err
- end
-
def test_help
out, err = capture_subprocess_io do
assert_equal(true, arv_put('-h'),
assert_equal '', out
end
+ def test_read_from_implicit_stdin
+ test_read_from_stdin(specify_stdin_as='--manifest')
+ end
+
def test_read_from_dev_stdin
test_read_from_stdin(specify_stdin_as='/dev/stdin')
end