1 /** 2 * Copyright: Copyright Jason White, 2016 3 * License: MIT 4 * Authors: Jason White 5 * 6 * Description: 7 * Handles command line arguments. 8 */ 9 module button.cli.help; 10 11 import button.cli.options; 12 13 import io.text, io.file.stdio; 14 15 import darg; 16 17 int displayHelp(string command) 18 { 19 import io.text; 20 import std.traits : getUDAs; 21 22 foreach (Options; OptionsList) 23 { 24 alias commands = getUDAs!(Options, Command); 25 foreach (c; commands) 26 { 27 if (c.name == command) 28 { 29 enum usage = usageString!Options("button "~ commands[0].name); 30 31 alias descriptions = getUDAs!(Options, Description); 32 static if(descriptions.length > 0) 33 enum help = helpString!Options(descriptions[0].description); 34 else 35 enum help = helpString!Options(); 36 37 static if (usage !is null) 38 println(usage); 39 static if (help !is null) 40 println(help); 41 42 return 0; 43 } 44 } 45 } 46 47 printfln("No help available for '%s'.", command); 48 return 1; 49 } 50 51 private immutable string generalHelp = q"EOS 52 The most commonly used commands are: 53 build Builds based on changes. 54 graph Writes the build description in GraphViz format. 55 help Prints help on a specific command. 56 57 Use 'button help <command>' to get help on a specific command. 58 EOS"; 59 60 /** 61 * Display help information. 62 */ 63 int helpCommand(HelpOptions opts, GlobalOptions globalOpts) 64 { 65 if (opts.command) 66 return displayHelp(opts.command); 67 68 println(globalUsage); 69 println(globalHelp); 70 println(generalHelp); 71 return 0; 72 } 73 74 /** 75 * Display version information. 76 */ 77 int displayVersion(VersionOptions opts, GlobalOptions globalOpts) 78 { 79 stdout.println("button version 0.1.0"); 80 return 0; 81 }