Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
api:shell [2014/07/07 12:15]
vexatos
api:shell [2019/12/31 01:30] (current)
is2511 [Shell API] Tiny tiny fix `op` -> `ops`
Line 27: Line 27:
   Returns values similar to `pcall` and `coroutine.resume`:​ the first returned value is a boolean indicating success or error. In case of errors, the second returned value is a detailed error message. Otherwise the remaining returned values are the values that were returned by the specified program when it terminated.   Returns values similar to `pcall` and `coroutine.resume`:​ the first returned value is a boolean indicating success or error. In case of errors, the second returned value is a detailed error message. Otherwise the remaining returned values are the values that were returned by the specified program when it terminated.
 - `shell.parse(...):​ table, table`  ​ - `shell.parse(...):​ table, table`  ​
-  Utility methods intended for programs to parse their arguments. Will return two tables, the first one containing any "​normal"​ parameters, the second containing "​options"​. Options are indicated by a leading `-`, and all options must only be a single character, since multiple characters following a single `-` will be interpreted as multiple options. ​For exampleif a program is called like this: +  Utility methods intended for programs to parse their arguments. Will return two tables, the first one containing any "​normal"​ parameters, the second containing "​options"​. Options are indicated by a leading `-`, and all options must only be a single character, since multiple characters following a single `-` will be interpreted as multiple options. ​Options specified with 2 dashes are not split and can have multiple letters. Also2-dash options can be given values by using an equal sign. The following examples all assume the script `program` parses the options using `local args, ops = shell.parse(...)`. 
-  `program -abC -d arg1 arg2`   + 
-  ​And `programdoes `local argsoptions ​shell.parse(...)`, then `args` is the table `{"​arg1",​ "​arg2"​}`, and `options` is the table `{a=true,​b=true,​C=true,​d=true}`. +  `program` 
-- `shell.running([level:​ number]): string`   + 
-  ​Deprecateduse [[api:​process|process.running]].+  # `args` ​is `{}` 
 + 
 +  # `ops` is `{}`. 
 + 
 +  `program -abC -d arg1 arg2` 
 + 
 +  # `args` is `{"​arg1",​ "​arg2"​}` 
 + 
 +  ​`opsis `{a=true,b=true,​C=true,​d=true}`. 
 + 
 +  ​`program -abC --dog arg1 arg2` 
 + 
 +  # `args` is `{"​arg1",​ "​arg2"​}` 
 + 
 +  # `ops` is `{a=true,​b=true,​C=true,​dog=true}`. 
 + 
 +  `program ​-abC --dog=foo arg1 arg2` 
 + 
 +  # `args` is `{"​arg1",​ "​arg2"​}` 
 + 
 +  # `ops` is `{a=true,​b=true,​C=true,​dog="​foo"​}`. 
 + 
 +  On this next example, notice the single dash before ​`dog`, this causes all of the token to be parsed as single chars. 
 + 
 +  `program -abC -dog=foo arg1 arg2` 
 + 
 +  ​# `args` is `{"​arg1",​ "​arg2"​}` 
 + 
 +  # `ops` is `{a=true,​b=true,​C=true,​d=true,​g=true,["​="​]=true,​f=true,​o=true}`. 
  
 Contents Contents
 ----------- -----------
 {{page>​api:​contents&​noheader&​noeditbutton&​nouser&​nofooter}} {{page>​api:​contents&​noheader&​noeditbutton&​nouser&​nofooter}}