Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding real help.

  • Loading branch information...
commit b8bf4e211fad4f23d02637a57191c4c195d8d6d5 1 parent 1d18793
@akoprow akoprow authored
View
2  src/calc.opa
@@ -32,7 +32,7 @@ module Calc {
{ initial_state: void,
metadata: {
id: "calc",
- name: "Simple calculator",
+ description: "Simple calculator",
cmds: [ { cmd: "[EXPR]", description: "Calculates the result of the given expression, using operators: +, -, *, / and parenthesses" } ]
},
function parse_cmd(_) {
View
2  src/dropbox.opa
@@ -143,7 +143,7 @@ Please re-run your application with: --dropbox-config option")
{ initial_state: Dropbox.credentials {no_credentials},
metadata: {
id: "dropbox",
- name: "Dropbox file-storage",
+ description: "Managing Dropbox file storage",
cmds: [ { cmd: "ls", description: "Lists contents of the current directory" } ],
},
function parse_cmd(creds) {
View
2  src/search.opa
@@ -316,7 +316,7 @@ Please re-run your application with: --blekko-config option")
{ initial_state: void,
metadata: {
id: "search",
- name: "Blekko search",
+ description: "Performing web search with Blekko",
cmds: [ { cmd: "search [terms]", description: "Performs a web search with given keywords" },
{ cmd: "next", description: "Shows next page with results" },
{ cmd: "prev", description: "Shows previous page with results" },
View
39 src/service.opa
@@ -14,8 +14,8 @@ type Service.outcome('state) =
// meta-data about the service (for help)
type Service.metadata =
- { string id,
- string name,
+ { string id,
+ string description,
list({string cmd, string description}) cmds
}
@@ -125,11 +125,31 @@ server module Shell {
}
private function print_generic_help(mods) {
- <></>
+ function present_module(mod) {
+ <li><strong>{mod.id}</>: {mod.description}</>
+ }
+ <>Use: '<strong>help module</>' to get help about using given module. Available modules:
+ <ul>{List.map(present_module, mods)}</>
+ </>
}
- private function print_help_for(mods, mod) {
- <></>
+ private function print_help_for(mods, mod_name) {
+ function show_cmd(cmd) {
+ <li><strong>{cmd.cmd}</>: {cmd.description}</>
+ }
+ function show_help(mod) {
+ <>
+ <strong>{mod.id}</>: {mod.description}
+ <ul>{List.map(show_cmd, mod.cmds)}</>
+ </>
+ }
+ function good_module(m) { m.id == mod_name }
+ match (List.find(good_module, mods)) {
+ case {some: mod}: show_help(mod)
+ default:
+ all_modules = List.map(_.id, mods)
+ <>Unknown module: '{mod_name}'. Available modules: {List.to_string_using("", "", ", ", all_modules)}</>
+ }
}
private function core_parser(mods) {
@@ -147,13 +167,14 @@ server module Shell {
}
private function core_handler(mods) {
- { cmd_executor: core_executor(mods),
- metadata: {
- id: "core",
- name: "Core shell functionality",
+ metadata =
+ { id: "core",
+ description: "Core shell functionality",
cmds: [ { cmd: "clear", description: "Clear the shell screen" },
{ cmd: "help [module]", description: "Prints help about given 'module'. If module ommited prints all available modules." } ]
}
+ { cmd_executor: core_executor([metadata | List.map(_.metadata, mods)]),
+ ~metadata
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.