// Path: sshd-shell-spring-boot-starter/src/main/java/sshd/shell/springboot/console/ConsoleIO.java
// @lombok.extern.slf4j.Slf4j
// public enum ConsoleIO {
//     ;
// 
//     static final String LINE_READER = "__lineReader";
//     static final String TEXT_STYLE = "__textStyle";
//     static final String TERMINAL = "__terminal";
//     static final String HIGHLIGHT_COLOR = "__highlightColor";
// 
//     /**
//      * Read input from line with mask. Use null if input is to be echoed. Use 0 if nothing is to be echoed and other
//      * characters that get echoed with input
//      *
//      * @param text Text to show
//      * @param mask mask
//      * @return input from user
//      * @throws IOException if any
//      */
//     public static String readInput(String text, Character mask) throws IOException {
//         LineReader reader = SshSessionContext.<LineReader>get(LINE_READER);
//         AttributedStyle textStyle = SshSessionContext.<AttributedStyle>get(TEXT_STYLE);
//         Terminal terminal = SshSessionContext.<Terminal>get(TERMINAL);
//         String prompt = new AttributedStringBuilder()
//                 .style(textStyle)
//                 .append(text)
//                 .append(' ')
//                 .style(AttributedStyle.DEFAULT)
//                 .toAnsi(terminal);
//         return reader.readLine(prompt, mask);
//     }
// 
//     /**
//      * Read input from line with input echoed.
//      *
//      * @param text Text to show
//      * @return input from user
//      * @throws IOException if any
//      */
//     public static String readInput(String text) throws IOException {
//         return readInput(text, null);
//     }
// 
//     /**
//      * Write output.
//      *
//      * @param output Text output
//      */
//     public static void writeOutput(String output) {
//         writeOutput(output, null);
//     }
// 
//     /**
//      * Write highlighted output.
//      *
//      * @param output Text output
//      * @param textToHighlight text to highlight
//      */
//     public static void writeOutput(String output, String textToHighlight) {
//         Terminal terminal = SshSessionContext.<Terminal>get(TERMINAL);
//         AttributedStringBuilder builder = new AttributedStringBuilder()
//                 .style(SshSessionContext.<AttributedStyle>get(TEXT_STYLE));
//         if (Objects.isNull(textToHighlight)) {
//             builder.append(output);
//         } else {
//             addHighlightedTextToBuilder(output, textToHighlight, builder);
//         }
//         terminal.writer().println(builder.style(AttributedStyle.DEFAULT).toAnsi(terminal));
//         terminal.flush();
//     }
// 
//     private static void addHighlightedTextToBuilder(String output, String textToHighlight,
//             AttributedStringBuilder builder) {
//         String[] split = output.split(textToHighlight);
//         for (int i = 0; i < split.length - 1; i++) {
//             builder.append(split[i])
//                     .style(SshSessionContext.<AttributedStyle>get(HIGHLIGHT_COLOR))
//                     .append(textToHighlight)
//                     .style(SshSessionContext.<AttributedStyle>get(TEXT_STYLE));
//         }
//         builder.append(split[split.length - 1]);
//     }
// 
//     public static void writeJsonOutput(Object object) {
//         writeJsonOutput(object, null);
//     }
// 
//     public static void writeJsonOutput(Object object, String textToHighlight) {
//         writeOutput(JsonUtils.asJson(object), textToHighlight);
//     }
// }


import java.io.IOException;
import org.springframework.stereotype.Component;
import sshd.shell.springboot.autoconfiguration.SshdShellCommand;
import sshd.shell.springboot.console.ConsoleIO;
/**
 * 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 sshd.shell.springboot.command;


/**
 *
 * @author anand
 */
@Component
@SshdShellCommand(value = "test", description = "test description", roles = {"USER", "ADMIN"})
public class TestCommand {
    
    @SshdShellCommand(value = "run", description = "test run", roles = "USER")
    public String run(String arg) {
        return "test run " + arg;
    }
    
    @SshdShellCommand(value = "execute", description = "test execute", roles = "ADMIN")
    public String execute(String arg) {
        return "test execute successful";
    }
    
    @SshdShellCommand(value = "interactive", description = "test interactive")
    public String interactive(String arg) throws IOException {
// Path: sshd-shell-spring-boot-starter/src/main/java/sshd/shell/springboot/console/ConsoleIO.java
// @lombok.extern.slf4j.Slf4j
// public enum ConsoleIO {
//     ;
// 
//     static final String LINE_READER = "__lineReader";
//     static final String TEXT_STYLE = "__textStyle";
//     static final String TERMINAL = "__terminal";
//     static final String HIGHLIGHT_COLOR = "__highlightColor";
// 
//     /**
//      * Read input from line with mask. Use null if input is to be echoed. Use 0 if nothing is to be echoed and other
//      * characters that get echoed with input
//      *
//      * @param text Text to show
//      * @param mask mask
//      * @return input from user
//      * @throws IOException if any
//      */
//     public static String readInput(String text, Character mask) throws IOException {
//         LineReader reader = SshSessionContext.<LineReader>get(LINE_READER);
//         AttributedStyle textStyle = SshSessionContext.<AttributedStyle>get(TEXT_STYLE);
//         Terminal terminal = SshSessionContext.<Terminal>get(TERMINAL);
//         String prompt = new AttributedStringBuilder()
//                 .style(textStyle)
//                 .append(text)
//                 .append(' ')
//                 .style(AttributedStyle.DEFAULT)
//                 .toAnsi(terminal);
//         return reader.readLine(prompt, mask);
//     }
// 
//     /**
//      * Read input from line with input echoed.
//      *
//      * @param text Text to show
//      * @return input from user
//      * @throws IOException if any
//      */
//     public static String readInput(String text) throws IOException {
//         return readInput(text, null);
//     }
// 
//     /**
//      * Write output.
//      *
//      * @param output Text output
//      */
//     public static void writeOutput(String output) {
//         writeOutput(output, null);
//     }
// 
//     /**
//      * Write highlighted output.
//      *
//      * @param output Text output
//      * @param textToHighlight text to highlight
//      */
//     public static void writeOutput(String output, String textToHighlight) {
//         Terminal terminal = SshSessionContext.<Terminal>get(TERMINAL);
//         AttributedStringBuilder builder = new AttributedStringBuilder()
//                 .style(SshSessionContext.<AttributedStyle>get(TEXT_STYLE));
//         if (Objects.isNull(textToHighlight)) {
//             builder.append(output);
//         } else {
//             addHighlightedTextToBuilder(output, textToHighlight, builder);
//         }
//         terminal.writer().println(builder.style(AttributedStyle.DEFAULT).toAnsi(terminal));
//         terminal.flush();
//     }
// 
//     private static void addHighlightedTextToBuilder(String output, String textToHighlight,
//             AttributedStringBuilder builder) {
//         String[] split = output.split(textToHighlight);
//         for (int i = 0; i < split.length - 1; i++) {
//             builder.append(split[i])
//                     .style(SshSessionContext.<AttributedStyle>get(HIGHLIGHT_COLOR))
//                     .append(textToHighlight)
//                     .style(SshSessionContext.<AttributedStyle>get(TEXT_STYLE));
//         }
//         builder.append(split[split.length - 1]);
//     }
// 
//     public static void writeJsonOutput(Object object) {
//         writeJsonOutput(object, null);
//     }
// 
//     public static void writeJsonOutput(Object object, String textToHighlight) {
//         writeOutput(JsonUtils.asJson(object), textToHighlight);
//     }
// }


// Path: sshd-shell-spring-boot-starter/src/test/java/sshd/shell/springboot/command/TestCommand.java
import java.io.IOException;
import org.springframework.stereotype.Component;
import sshd.shell.springboot.autoconfiguration.SshdShellCommand;
import sshd.shell.springboot.console.ConsoleIO;

/**
 * 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 sshd.shell.springboot.command;


/**
 *
 * @author anand
 */
@Component
@SshdShellCommand(value = "test", description = "test description", roles = {"USER", "ADMIN"})
public class TestCommand {
    
    @SshdShellCommand(value = "run", description = "test run", roles = "USER")
    public String run(String arg) {
        return "test run " + arg;
    }
    
    @SshdShellCommand(value = "execute", description = "test execute", roles = "ADMIN")
    public String execute(String arg) {
        return "test execute successful";
    }
    
    @SshdShellCommand(value = "interactive", description = "test interactive")
    public String interactive(String arg) throws IOException {
        String name = ConsoleIO.readInput("Name:");