@Commands.command(
        'upload',
        aliases=('up',),
        help=[
            'Create a bundle by uploading an existing file/directory.',
            '  upload <path>            : Upload contents of file/directory <path> as a bundle.',
            '  upload <path> ... <path> : Upload one bundle whose directory contents contain <path> ... <path>.',
            '  upload -c <text>         : Upload one bundle whose file contents is <text>.',
            '  upload <url>             : Upload one bundle whose file contents is downloaded from <url>.',
            '  upload                   : Open file browser dialog and upload contents of the selected file as a bundle (website only).',
            'Most of the other arguments specify metadata fields.',
        ],
        arguments=(
            Commands.Argument('path', help='Paths (or URLs) of the files/directories to upload.', nargs='*', completer=require_not_headless(FilesCompleter())),
            Commands.Argument('-c', '--contents', help='Specify the string contents of the bundle.'),
            Commands.Argument('-L', '--follow-symlinks', help='Always dereference (follow) symlinks.', action='store_true'),
            Commands.Argument('-x', '--exclude-patterns', help='Exclude these file patterns.', nargs='*'),
            Commands.Argument('-g', '--git', help='Path is a git repository, git clone it.', action='store_true'),
            Commands.Argument('-p', '--pack', help='If path is an archive file (e.g., zip, tar.gz), keep it packed.', action='store_true', default=False),
            Commands.Argument('-w', '--worksheet-spec', help=WORKSHEET_SPEC_FORMAT % 'Upload to this worksheet (%s).', completer=WorksheetsCompleter),
        ) + Commands.metadata_arguments([UploadedBundle] + [get_bundle_subclass(bundle_type) for bundle_type in UPLOADED_TYPES])
        + EDIT_ARGUMENTS,
    )
    def do_upload_command(self, args):
        # If headless and no args provided, request an Upload dialog on the front end.
        if self.headless and not args.path and args.contents is None:
            return ui_actions.serialize([ui_actions.Upload()])

        client, worksheet_uuid = self.parse_client_worksheet_uuid(args.worksheet_spec)

        # Verify arguments are valid.
        for path in args.path:
            if path_util.path_is_url(path):
                # OK: We have already checked that there are no other bundles to upload.
                pass
            elif self.headless:
                # Important: don't allow uploading files if headless.
                raise UsageError("Cannot upload from path %s: no filesystem available." % path)
            else:
                # Check that the upload path exists.
                path_util.check_isvalid(path_util.normalize(path), 'upload')

        # If contents of file are specified on the command-line, then include that with the bundles to upload.
        if args.contents is not None:
            if not args.md_name:
                args.md_name = 'contents'
            tmp_path = tempfile.mkstemp()[1]
            f = open(tmp_path, 'w')
            print >>f, args.contents
            f.close()
            args.path.append(tmp_path)

        # Canonicalize (e.g., removing trailing /)
        sources = [path_util.normalize(path) for path in args.path]

        # Pull out the upload bundle type from the arguments and validate it.
        # Note: only allow dataset bundles (eventually deprecate the program bundle and just have uploaded bundles).
        bundle_type = 'dataset'
        bundle_subclass = get_bundle_subclass(bundle_type)
        metadata = self.get_missing_metadata(bundle_subclass, args, initial_metadata={})
        # name = 'test.zip' => name = 'test'
        if not args.pack and zip_util.path_is_archive(metadata['name']):
            metadata['name'] = zip_util.strip_archive_ext(metadata['name'])

        # Type-check the bundle metadata BEFORE uploading the bundle data.
        # This optimization will avoid file copies on failed bundle creations.
        # pass in a null owner to validate. Will be set to the correct owner in the client upload_bundle below.
        bundle_subclass.construct(owner_id=0, metadata=metadata).validate()
        info = {'bundle_type': bundle_type, 'metadata': metadata}

        # Finally, once everything has been checked, then call the client to upload.
        uuid = client.upload_bundle(
            sources=sources,
            follow_symlinks=args.follow_symlinks,
            exclude_patterns=args.exclude_patterns,
            git=args.git,
            unpack=not args.pack,
            remove_sources=(args.contents is not None),
            info=info,
            worksheet_uuid=worksheet_uuid,
            add_to_worksheet=True,
        )
        print >>self.stdout, uuid
dataset/ETHPy150Open codalab/codalab-cli/codalab/lib/bundle_cli.py/BundleCLI.do_upload_command/swapped operands of `%`