001package crash.commands.base; 002 003import org.crsh.cli.Command; 004import org.crsh.cli.Usage; 005import org.crsh.command.BaseCommand; 006import org.crsh.command.InvocationContext; 007import org.crsh.shell.impl.command.CRaSH; 008import org.crsh.text.Color; 009import org.crsh.text.Decoration; 010import org.crsh.text.Style; 011import org.crsh.text.ui.LabelElement; 012import org.crsh.text.ui.RowElement; 013import org.crsh.text.ui.TableElement; 014 015import java.io.IOException; 016 017/** @author Julien Viet */ 018public class help extends BaseCommand { 019 020 @Usage("provides basic help") 021 @Command 022 public void main(InvocationContext<Object> context) throws IOException { 023 024 // 025 TableElement table = new TableElement().rightCellPadding(1); 026 table.add( 027 new RowElement(). 028 add(new LabelElement("NAME").style(Style.style(Decoration.bold))). 029 add(new LabelElement("DESCRIPTION"))); 030 031 // 032 CRaSH crash = (CRaSH)context.getSession().get("crash"); 033 Iterable<String> names = crash.getCommandNames(); 034 for (String name : names) { 035 try { 036 String desc = crash.getCommandDescription(name); 037 if (desc == null) { 038 desc = ""; 039 } 040 table.add( 041 new RowElement(). 042 add(new LabelElement(name).style(Style.style(Color.red))). 043 add(new LabelElement(desc))); 044 } catch (Exception ignore) { 045 // 046 } 047 } 048 049 // 050 context.provide(new LabelElement("Try one of these commands with the -h or --help switch:\n")); 051 context.provide(table); 052 } 053}