/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.pdfbox.tools;

import java.io.PrintStream;

import org.apache.pdfbox.debugger.PDFDebugger;

import picocli.CommandLine;
import picocli.CommandLine.Command;

/**
 * Simple wrapper around all the command line utilities included in PDFBox.
 * Used as the main class in the runnable standalone PDFBox jar.
 */
@Command(name="PDFBox", subcommands = {
    PDFDebugger.class,
    Decrypt.class,
    Encrypt.class,
    ExtractText.class,
    ExtractImages.class,
    OverlayPDF.class,
    PrintPDF.class,
    PDFMerger.class,
    PDFSplit.class,
    PDFToImage.class,
    ImageToPDF.class,
    TextToPDF.class,
    WriteDecodedDoc.class,
}, versionProvider = Version.class, mixinStandardHelpOptions = true)
public final class PDFBox implements Runnable
{
    // Expected for CLI app to write to System.out/Sytem.err
    @SuppressWarnings("squid:S106")
    private static final PrintStream SYSOUT = System.out;
  
    /**
     * Main method.
     * 
     * @param args command line arguments
     */
    public static void main(String[] args)
    {
        // suppress the Dock icon on OS X
        System.setProperty("apple.awt.UIElement", "true");

        CommandLine cmd = new CommandLine(new PDFBox());
        cmd.execute(args);
    
        if (args.length == 0) { cmd.usage(SYSOUT); }
    }

    @Override
    public void run()
    {
        // stub method to please the Runnable interface needed by picocli
    }
}

@@ -834,37 +834,8 @@
 s;%0A%0A
-import java.io.PrintStream;%0A%0A
 impo
@@ -941,16 +941,96 @@
 Command;
+%0Aimport picocli.CommandLine.ParameterException;%0Aimport picocli.CommandLine.Spec;
 %0A%0A/**%0A *
@@ -1195,16 +1195,168 @@
 PDFBox%22,
+%0A    customSynopsis = %22PDFBox %5BCOMMAND%5D %5BOPTIONS%5D%22,%0A    footer = %7B%0A        %22See 'PDFBox help %3Ccommand%3E' to read about a specific subcommand.%22%0A    %7D,%0A   
  subcomm
@@ -1368,16 +1368,20 @@
 = %7B%0A    
+ 
+   
 PDFDebug
@@ -1395,16 +1395,20 @@
 ss,%0A    
+   
+ 
 Decrypt.
@@ -1410,24 +1410,28 @@
 rypt.class,%0A
+    
     Encrypt.
@@ -1429,32 +1429,36 @@
  Encrypt.class,%0A
+    
     ExtractText.
@@ -1464,24 +1464,28 @@
 .class,%0A    
+  
+  
 ExtractImage
@@ -1489,24 +1489,28 @@
 ages.class,%0A
+    
     OverlayP
@@ -1515,24 +1515,28 @@
 yPDF.class,%0A
+    
     PrintPDF
@@ -1547,16 +1547,20 @@
 ss,%0A    
+  
+  
 PDFMerge
@@ -1572,16 +1572,20 @@
 ss,%0A    
+   
+ 
 PDFSplit
@@ -1588,24 +1588,28 @@
 plit.class,%0A
+    
     PDFToIma
@@ -1622,16 +1622,20 @@
 ss,%0A    
+ 
+   
 ImageToP
@@ -1648,16 +1648,20 @@
 ss,%0A    
+  
+  
 TextToPD
@@ -1665,24 +1665,28 @@
 oPDF.class,%0A
+    
     WriteDec
@@ -1704,283 +1704,187 @@
 ss,%0A
-%7D, versionProvider = Version.class, mixinStandardHelpOptions = true)%0Apublic final class PDFBox implements Runnable%0A%7B%0A    // Expected for CLI app to write to System.out/Sytem.err%0A    @SuppressWarnings(%22squid:S106%22)%0A    private static final PrintStream SYSOUT = System.out
+        CommandLine.HelpCommand.class%0A    %7D,%0A    versionProvider = Version.class)%0Apublic final class PDFBox implements Runnable%0A%7B%0A    @Spec CommandLine.Model.CommandSpec spec
 ;%0A
+%0A
   
-%0A
     
@@ -2127,26 +2127,8 @@
     
- CommandLine cmd =
  new
@@ -2157,21 +2157,8 @@
 x())
-;%0A        cmd
 .exe
@@ -2177,184 +2177,140 @@
     
-%0A        if (args.length == 0) %7B cmd.usage(SYSOUT); %7D%0A    %7D%0A%0A    @Override%0A    public void run()%0A    %7B%0A        // stub method to please the Runnable interface needed by picocli
+%7D%0A%0A    @Override%0A    public void run()%0A    %7B%0A        throw new ParameterException(spec.commandLine(), %22Error: Subcommand required%22);
 %0A   

add footer; custom synopsis