Package jline.console

Examples of jline.console.ConsoleReader


        GeoGIG geogig = cli.getGeogig();

        if (!refSpecs.isEmpty()) {
            checkParameter(!(resolve_geogig_dir || is_inside_work_tree),
                    "if refSpec is given, --resolve-geogig-dir or --is-inside-work-tree shall not be specified");
            ConsoleReader console = cli.getConsole();
            for (String refSpec : this.refSpecs) {
                Optional<ObjectId> resolved = geogig
                        .command(org.locationtech.geogig.api.plumbing.RevParse.class)
                        .setRefSpec(refSpec).call();
                checkParameter(resolved.isPresent(), "fatal: ambiguous argument '%s': "
                        + "unknown revision or path not in the working tree.", refSpec);
                console.println(resolved.get().toString());
            }
            console.flush();
            return;
        }

        boolean closeIt = false;
        if (null == geogig) {
View Full Code Here


    private List<String> patterns = new ArrayList<String>();

    @Override
    public void runInternal(GeogigCLI cli) throws IOException {

        ConsoleReader console = cli.getConsole();
        GeoGIG geogig = cli.getGeogig();

        ForEachRef op = geogig.command(ForEachRef.class);

        Predicate<Ref> filter = new Predicate<Ref>() {
            @Override
            public boolean apply(Ref ref) {
                String name = ref.getName();
                if (!name.startsWith(Ref.REFS_PREFIX)) {
                    return false;
                }
                boolean match = patterns.isEmpty() ? true : false;
                for (String pattern : patterns) {
                    if (Strings.isNullOrEmpty(pattern)) {
                        match = true;
                    } else if (name.endsWith("/" + pattern)) {
                        match = true;
                        break;
                    }
                }
                return match;
            }
        };
        op.setFilter(filter);

        ImmutableSet<Ref> refs = op.call();

        for (Ref ref : refs) {
            console.println(ref.getObjectId() + " " + ref.getName());
        }
    }
View Full Code Here

    @Override
    public void runInternal(GeogigCLI cli) throws IOException {
        checkParameter(paths.size() < 2, "Only one refspec allowed");
        checkParameter(!paths.isEmpty(), "A refspec must be specified");

        ConsoleReader console = cli.getConsole();
        GeoGIG geogig = cli.getGeogig();

        String path = paths.get(0);

        Optional<RevObject> obj = geogig.command(RevObjectParse.class).setRefSpec(path).call();
        checkParameter(obj.isPresent(), "refspec did not resolve to any object.");
        if (binary) {
            ObjectSerializingFactory factory = DataStreamSerializationFactoryV1.INSTANCE;
            ObjectWriter<RevObject> writer = factory.createObjectWriter(obj.get().getType());
            writer.write(obj.get(), System.out);
        } else {
            CharSequence s = geogig.command(CatObject.class)
                    .setObject(Suppliers.ofInstance(obj.get())).call();
            console.println(s);
        }
    }
View Full Code Here

     */
    @Override
    public void runInternal(GeogigCLI cli) throws IOException {
        checkParameter(limit >= 0, "Limit must be 0 or greater.");

        ConsoleReader console = cli.getConsole();
        GeoGIG geogig = cli.getGeogig();

        StatusOp op = geogig.command(StatusOp.class);
        StatusSummary summary = op.call();

        final Optional<Ref> currHead = geogig.command(RefParse.class).setName(Ref.HEAD).call();
        checkParameter(currHead.isPresent(), "Repository has no HEAD.");

        if (currHead.get() instanceof SymRef) {
            final SymRef headRef = (SymRef) currHead.get();
            console.println("# On branch " + Ref.localName(headRef.getTarget()));
        } else {
            console.println("# Not currently on any branch.");
        }

        print(console, summary);

    }
View Full Code Here

    private List<String> pathsToRemove = new ArrayList<String>();

    @Override
    public void runInternal(GeogigCLI cli) throws IOException {

        ConsoleReader console = cli.getConsole();

        // check that there is something to remove
        if (pathsToRemove.isEmpty()) {
            printUsage(cli);
            throw new CommandFailedException();
        }

        /*
         * Separate trees and features, and check that, if there are trees to remove, the -r
         * modifier is used
         */
        ArrayList<String> trees = new ArrayList<String>();
        Repository repository = cli.getGeogig().getRepository();
        for (String pathToRemove : pathsToRemove) {
            NodeRef.checkValidPath(pathToRemove);

            Optional<NodeRef> node = repository.command(FindTreeChild.class)
                    .setParent(repository.workingTree().getTree()).setIndex(true)
                    .setChildPath(pathToRemove).call();
            checkParameter(node.isPresent(), "pathspec '%s' did not match any feature or tree",
                    pathToRemove);
            NodeRef nodeRef = node.get();
            if (nodeRef.getType() == TYPE.TREE) {
                checkParameter(recursive, "Cannot remove tree %s if -r is not specified",
                        nodeRef.path());
                trees.add(pathToRemove);
            }
        }
        int featuresCount = pathsToRemove.size() - trees.size();

        /* Perform the remove operation */
        RemoveOp op = cli.getGeogig().command(RemoveOp.class);

        for (String pathToRemove : pathsToRemove) {
            op.addPathToRemove(pathToRemove);
        }

        op.setProgressListener(cli.getProgressListener()).call();

        /* And inform about it */
        if (featuresCount > 0) {
            console.print(String.format("Deleted %d feature(s)", featuresCount));
        }

        for (String tree : trees) {
            console.print(String.format("Deleted %s tree", tree));
        }

    }
View Full Code Here

    @Parameter(names = { "--dry-run", "-n" }, description = "Don't actually remove anything, just show what would be done.")
    private boolean dryRun;

    @Override
    public void runInternal(GeogigCLI cli) throws IOException {
        final ConsoleReader console = cli.getConsole();
        final GeoGIG geogig = cli.getGeogig();

        String pathFilter = null;
        if (!path.isEmpty()) {
            pathFilter = path.get(0);
        }

        if (dryRun) {
            if (pathFilter != null) {
                // check that is a valid path
                Repository repository = cli.getGeogig().getRepository();
                NodeRef.checkValidPath(pathFilter);

                Optional<NodeRef> ref = repository.command(FindTreeChild.class).setIndex(true)
                        .setParent(repository.workingTree().getTree()).setChildPath(pathFilter)
                        .call();

                checkParameter(ref.isPresent(), "pathspec '%s' did not match any tree", pathFilter);
                checkParameter(ref.get().getType() == TYPE.TREE,
                        "pathspec '%s' did not resolve to a tree", pathFilter);
            }
            Iterator<DiffEntry> unstaged = geogig.command(DiffWorkTree.class).setFilter(pathFilter)
                    .call();
            while (unstaged.hasNext()) {
                DiffEntry entry = unstaged.next();
                if (entry.changeType() == ChangeType.ADDED) {
                    console.println("Would remove " + entry.newPath());
                }
            }
        } else {
            geogig.command(CleanOp.class).setPath(pathFilter).call();
            console.println("Clean operation completed succesfully.");
        }
    }
View Full Code Here

        InputStream in = new ByteArrayInputStream(new byte[0]);
        // dumps output to a temp file if > threshold
        FileBackedOutputStream out = new FileBackedOutputStream(4096);
        try {
            // pass it a BufferedOutputStream 'cause it doesn't buffer the internal FileOutputStream
            ConsoleReader console = new ConsoleReader(in, new BufferedOutputStream(out),
                    new UnsupportedTerminal());
            Platform platform = geogig.getPlatform();

            GeogigCLI geogigCLI = new GeogigCLI(geogig, console);
            geogigCLI.setPlatform(platform);
View Full Code Here

    public GeogigPy4JEntryPoint() {
        listener = new SilentProgressListener();
        os = new ToStringOutputStream();
        stream = new PrintStream(os);
        try {
            consoleReader = new ConsoleReader(System.in, stream);
            consoleReader.getTerminal().setEchoEnabled(true);
        } catch (Exception e) {
            throw Throwables.propagate(e);
        }
    }
View Full Code Here

    @Override
    public void runInternal(GeogigCLI cli) throws IOException {
        checkParameter(patchFiles.size() < 2, "Only one single patch file accepted");
        checkParameter(!patchFiles.isEmpty(), "No patch file specified");

        ConsoleReader console = cli.getConsole();
        GeoGIG geogig = cli.getGeogig();

        File patchFile = new File(patchFiles.get(0));
        checkParameter(patchFile.exists(), "Patch file cannot be found");
        FileInputStream stream;
        try {
            stream = new FileInputStream(patchFile);
        } catch (FileNotFoundException e1) {
            throw new CommandFailedException("Can't open patch file " + patchFile, e1);
        }
        BufferedReader reader = null;
        try {
            reader = new BufferedReader(new InputStreamReader(stream, "UTF-8"));
        } catch (UnsupportedEncodingException e) {
            Closeables.closeQuietly(reader);
            Closeables.closeQuietly(stream);
            throw new CommandFailedException("Error reading patch file " + patchFile, e);
        }
        Patch patch = PatchSerializer.read(reader);
        Closeables.closeQuietly(reader);
        Closeables.closeQuietly(stream);

        if (reverse) {
            patch = patch.reversed();
        }

        if (summary) {
            console.println(patch.toString());
        } else if (check) {
            VerifyPatchResults verify = cli.getGeogig().command(VerifyPatchOp.class)
                    .setPatch(patch).call();
            Patch toReject = verify.getToReject();
            Patch toApply = verify.getToApply();
            if (toReject.isEmpty()) {
                console.println("Patch can be applied.");
            } else {
                console.println("Error: Patch cannot be applied\n");
                console.println("Applicable entries:\n");
                console.println(toApply.toString());
                console.println("\nConflicting entries:\n");
                console.println(toReject.toString());
            }
        } else {
            try {
                Patch rejected = geogig.command(ApplyPatchOp.class).setPatch(patch)
                        .setApplyPartial(reject).call();
                if (reject) {
                    if (rejected.isEmpty()) {
                        console.println("Patch applied succesfully");
                    } else {
                        int accepted = patch.count() - rejected.count();
                        StringBuilder sb = new StringBuilder();
                        File file = new File(patchFile.getAbsolutePath() + ".rej");
                        sb.append("Patch applied only partially.\n");
                        sb.append(Integer.toString(accepted) + " changes were applied.\n");
                        sb.append(Integer.toString(rejected.count()) + " changes were rejected.\n");
                        BufferedWriter writer = Files.newWriter(file, Charsets.UTF_8);
                        PatchSerializer.write(writer, patch);
                        writer.flush();
                        writer.close();
                        sb.append("Patch file with rejected changes created at "
                                + file.getAbsolutePath() + "\n");
                        throw new CommandFailedException(sb.toString());
                    }
                } else {
                    console.println("Patch applied succesfully");
                }
            } catch (CannotApplyPatchException e) {
                throw new CommandFailedException(e);
            }
View Full Code Here

    private GeogigCLI cli;

    @Before
    public void setUp() throws Exception {
        ConsoleReader consoleReader = new ConsoleReader(System.in, System.out,
                new UnsupportedTerminal());
        cli = new GeogigCLI(consoleReader);

        setUpGeogig(cli);
    }
View Full Code Here

TOP

Related Classes of jline.console.ConsoleReader

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.