001// SPDX-FileCopyrightText: 2021 Paul Schaub <vanitasvitae@fsfe.org>
002//
003// SPDX-License-Identifier: Apache-2.0
004
005package sop.cli.picocli.commands;
006
007import java.io.IOException;
008
009import picocli.CommandLine;
010import sop.cli.picocli.Print;
011import sop.cli.picocli.SopCLI;
012import sop.exception.SOPGPException;
013
014@CommandLine.Command(name = "dearmor",
015        description = "Remove ASCII Armor from standard input",
016        exitCodeOnInvalidInput = SOPGPException.UnsupportedOption.EXIT_CODE)
017public class DearmorCmd implements Runnable {
018
019    @Override
020    public void run() {
021        try {
022            SopCLI.getSop()
023                    .dearmor()
024                    .data(System.in)
025                    .writeTo(System.out);
026        } catch (SOPGPException.BadData e) {
027            Print.errln("Bad data.");
028            Print.trace(e);
029            System.exit(e.getExitCode());
030        } catch (IOException e) {
031            Print.errln("IO Error.");
032            Print.trace(e);
033            System.exit(1);
034        }
035    }
036}