Commit Graph

321 Commits

Author SHA1 Message Date
Brian Tiger Chow
ef0826acd6 fix(commands/err)
I didn't know there were dragons here.

When casting errors we've gotta be careful. Apparently both values and
pointers satisfy the error interface. Type checking for one doesn't
catch the other.

cc @whyrusleeping @mappum @jbenet

License: MIT
Signed-off-by: Brian Tiger Chow <brian@perfmode.com>
2014-11-14 03:20:07 -08:00
Brian Tiger Chow
ca2828f33c feat(commands) add ClientError(msg) helper and use it to return a fancy error to the client in the tour
@jbenet this exists now

License: MIT
Signed-off-by: Brian Tiger Chow <brian@perfmode.com>
2014-11-14 03:20:07 -08:00
Matt Bell
db361d9403 commands/cli: Made Parse return an error if request has unrecognized options 2014-11-14 03:20:06 -08:00
Juan Batiz-Benet
047d2e2d62 cmd2: Marshaller -> Marshaler (see golang/encoding)
Also:
- map[cmds.EncodingType]cmds.Marshaller -> MarshalMap

cc @mappum @maybebtc
2014-11-14 03:20:05 -08:00
Matt Bell
3b407c705d commands: Ensure command output is correct type (if cmd.Type is set), resolves #321 2014-11-14 03:20:05 -08:00
Juan Batiz-Benet
81b3680908 cmds2: aligned subcmd text 2014-11-14 03:20:05 -08:00
Matt Bell
646920b0dd commands: Got rid of old helptext fields, use HelpText struct fields in helptext generator 2014-11-14 03:20:05 -08:00
Brian Tiger Chow
e6c5fc250c docs(commands) todo
License: MIT
Signed-off-by: Brian Tiger Chow <brian@perfmode.com>
2014-11-14 03:20:04 -08:00
Brian Tiger Chow
562500491f test(commands/parse) take args instead of cmd for easier testing
@mappum

License: MIT
Signed-off-by: Brian Tiger Chow <brian@perfmode.com>
2014-11-14 03:20:04 -08:00
Matt Bell
28306a49c4 commands/cli,http: Properly preserve argument value count when checking argument validity 2014-11-14 03:20:04 -08:00
Brian Tiger Chow
27b9aec370 style(commands/cli/helptext) use helper function to cut down on
boilerplate

I know you'll love this one @mappum

License: MIT
Signed-off-by: Brian Tiger Chow <brian@perfmode.com>
2014-11-14 03:20:04 -08:00
Brian Tiger Chow
5a9de188d7 fix(commands/request) return err when unable to load config/node due to
nil function

cc @jbenet @mappum

License: MIT
Signed-off-by: Brian Tiger Chow <brian@perfmode.com>
2014-11-14 03:20:04 -08:00
Matt Bell
9afb85714a commands/cli: Don't return root in Parse 2014-11-14 03:20:03 -08:00
Juan Batiz-Benet
7daf888902 cmds2: handle error return codes 2014-11-14 03:20:03 -08:00
Juan Batiz-Benet
d18902df27 cmds2: changed how the ctx.Node works 2014-11-14 03:20:02 -08:00
Juan Batiz-Benet
3352aeee15 cmds2: fixed show help on root + noncallable 2014-11-14 03:20:02 -08:00
Juan Batiz-Benet
f738e899c2 cmd2: simplified main
Attention @maybebtc @mappum

I cleaned up + simplified the main flow. Now, all printing
is contained inside main itself! (:cheer:). I do this with
the help of a cmdInvocation struct that has both
a Parse and Run. The only major clunkiness left is that the
"CallCommand" is still its own function. But *shrug*.

Please test it works as we would expect. i changed much of
the flow, so likely that i missed a complicated edge case.

main roadmap:
- parse the commandline to get a cmdInvocation
- if user requests, help, print it and exit.
- run the command invocation
- output the response
- if anything fails, print error, maybe with help
2014-11-14 03:20:02 -08:00
Matt Bell
3e7592f2cc commands/cli: Sort options by length when generating options helptext 2014-11-14 03:20:02 -08:00
Matt Bell
e41f861f8a commands/cli: Added some TODOs to Parse 2014-11-14 03:20:02 -08:00
Juan Batiz-Benet
b836e72aea cmd2 align arguments properly 2014-11-14 03:20:00 -08:00
Juan Batiz-Benet
c0b3b43773 cmds2/helptext moved indent + tagline in subcmd 2014-11-14 03:20:00 -08:00
Matt Bell
80d743541e commands/cli: Fixed spacing error 2014-11-14 03:20:00 -08:00
Juan Batiz-Benet
ef4480fe6d cmds/config: better help text 2014-11-14 03:20:00 -08:00
Juan Batiz-Benet
fc7c199d6a cmds/helptext: indent + newlines + synopsis 2014-11-14 03:20:00 -08:00
Matt Bell
8aa532fbc9 commands/cli: Less line breaks in autogenerated formatting 2014-11-14 03:20:00 -08:00
Juan Batiz-Benet
c25bf522d6 newline in short helptext 2014-11-14 03:19:59 -08:00
Matt Bell
47987f5df5 commands/cli: Transitionary commit - Generate helptext from HelpText fields if they aren't empty 2014-11-14 03:19:59 -08:00
Matt Bell
475f3f485b commands: Added HelpText struct to organize different help text fields in Commands 2014-11-14 03:19:59 -08:00
Brian Tiger Chow
7116591351 docs(commands/request) 2014-11-14 03:19:59 -08:00
Brian Tiger Chow
192377a852 fix(commands/optionvalue) use the util.ErrCast() 2014-11-14 03:19:59 -08:00
Brian Tiger Chow
c46102cec5 fix(commands/http/handler) check if found
@mappum, could you CR this and let me know if I've interpreted the
desired behavior correctly?
2014-11-14 03:19:57 -08:00
Brian Tiger Chow
bff646fb26 fix(commands/optionvalue) don't shadow the return variable
NB: return variables are provided for clarity. Otherwise, it's not
entirely clear that the bool is for _found_.
2014-11-14 03:19:57 -08:00
Brian Tiger Chow
3c4f628493 tests(commands/option) test the OptionValue methods
TODO add tests for remaning, untested methods.
2014-11-14 03:19:57 -08:00
Brian Tiger Chow
69374b30be refactor(commands/optionvalue) use
@mappum this optionvalue is a really great abstraction. It makes
maintenance super simple!

@jbenet @whyrusleeping
2014-11-14 03:19:57 -08:00
Brian Tiger Chow
71e92dace2 explain(commands/http)
we've gotta allow the code to speak for itself. I wouldn't have been
able to safely modify this code without having my hand held. I am but a
lowly programmer with a simple mind.

cc @jbenet @whyrusleeping @mappum
2014-11-14 03:19:57 -08:00
Brian Tiger Chow
9f801561fd feat(commands) add cast error 2014-11-14 03:19:57 -08:00
Matt Bell
a4e68c241b commands/http: Get string representations of option values when creating querystring 2014-11-14 03:19:57 -08:00
Juan Batiz-Benet
49792b2362 refactored cast errors to use a util 2014-11-14 03:19:56 -08:00
Matt Bell
81dbb23602 commands: Cleanup Requests after command execution returns 2014-11-14 03:17:43 -08:00
Matt Bell
8c9ee52a93 commands: Fixed value mutation bug in Request#SetOption 2014-11-14 03:17:42 -08:00
Brian Tiger Chow
94e8218be8 add todo 2014-11-14 03:17:42 -08:00
Matt Bell
93c69a83e8 commands/cli: Added short help text function 2014-11-14 03:17:41 -08:00
Matt Bell
4970d8b5a3 commands/cli: Use template for helptext generation 2014-11-14 03:17:41 -08:00
Brian Tiger Chow
ea15bd6ffe docs(commands) amend 2014-11-14 03:17:41 -08:00
Brian Tiger Chow
e6f2de40dc docs(commands) Type 2014-11-14 03:17:41 -08:00
Brian Tiger Chow
f5973b5565 add urgent todo. fix before merge 2014-11-14 03:17:41 -08:00
Matt Bell
7666f8880c commands: Allow overriding helptext sections with hand-written strings 2014-11-14 03:17:41 -08:00
Matt Bell
f93b806d21 commands/http: s/lenRequired/numRequired/ 2014-11-14 03:17:40 -08:00
Matt Bell
50751617b6 commands: s/j/valueIndex/ 2014-11-14 03:17:40 -08:00
Matt Bell
eedc2e9cc7 commands: s/lenRequired/numRequired/ 2014-11-14 03:17:40 -08:00
Matt Bell
e14471f5e8 commands/cli: Use better variable name for parseArgs value index 2014-11-14 03:17:40 -08:00
Matt Bell
5481230679 commands/cli: Use better temp variable names in Parse 2014-11-14 03:17:40 -08:00
Matt Bell
f48ce10efb commands/cli: Added comment to explain multiple root support in Parse 2014-11-14 03:17:40 -08:00
Matt Bell
40e96a1fa6 commands: Added Argument helper constructors 2014-11-14 03:17:39 -08:00
Matt Bell
f1fc26e70b commands: Removed a fmt.Println 2014-11-14 03:17:38 -08:00
Matt Bell
a9bd172414 commands: Fixed handling of int/uint option values 2014-11-14 03:17:38 -08:00
Matt Bell
3e507f7c9f commands: Changed option accessor API (Request#Option now returns an OptionValue) 2014-11-14 03:17:38 -08:00
Matt Bell
20591c7e64 commands: Made SetOption override existing values (even if they used a different alias) 2014-11-14 03:17:37 -08:00
Matt Bell
e34a0fd658 commands: Updated tests 2014-11-14 03:17:37 -08:00
Matt Bell
eebb43753b commands: Added list of option definitions to Request, so Option can lookup values by all aliases 2014-11-14 03:17:37 -08:00
Matt Bell
ce28fa363b commands: Fixed tests 2014-11-14 03:17:37 -08:00
Matt Bell
38b31c65f8 commands: Added Option helper constructors 2014-11-14 03:17:37 -08:00
Matt Bell
2029168e98 commands: Made Command run functions return (interface{}, error) instead of setting the values in the response 2014-11-14 03:17:37 -08:00
Matt Bell
f1c788d710 commands/http: Don't set Content-Type for stream outputs so browsers can MIME-sniff the actual content type 2014-11-14 03:17:35 -08:00
Matt Bell
5a18554f6e commands: Fixed tests 2014-11-14 03:17:35 -08:00
Matt Bell
20285ead82 commands: Indent JSON-marshalled Response output 2014-11-14 03:17:34 -08:00
Matt Bell
cdf221078d commands: Fixed tests 2014-11-14 03:17:34 -08:00
Matt Bell
3255bb02d1 commands/cli: Output command path in Parse 2014-11-14 03:17:34 -08:00
Matt Bell
c827573e32 commands/cli: Helptext spacing fix for root command output 2014-11-14 03:17:33 -08:00
Matt Bell
c169fca5a2 commands/cli: Added a helptext generator 2014-11-14 03:17:33 -08:00
Matt Bell
351ed9589a commands: Added 'Description' fields to Command, Argument, Option 2014-11-14 03:17:33 -08:00
Matt Bell
3df5202f8a commands/http: Log incoming requests (with DEBUG log level) 2014-11-14 03:17:30 -08:00
Matt Bell
cb72868ab4 commands: Fixed parser argument bug (TODO: better test coverage for command parsers) 2014-11-14 03:17:28 -08:00
Matt Bell
83cda2e699 commands/http: Fixed arg parse bug 2014-11-14 03:17:27 -08:00
Matt Bell
fecb434ab4 commands: Fixed arg validation bug 2014-11-14 03:17:27 -08:00
Matt Bell
1ee6c7e5f2 commands/cli: Fixed arg parse bug 2014-11-14 03:17:27 -08:00
Matt Bell
48c108d523 commands/cli: Made Parse return the resolved subcommand, even on error 2014-11-14 03:17:27 -08:00
Matt Bell
37f05a8bf6 commands: Ensure argument parsing maintains total argument count, so that argument validation will fail if there are too many 2014-11-14 03:17:27 -08:00
Matt Bell
116041c5ec commands: Fixed argument value/definition mapping 2014-11-14 03:17:26 -08:00
Brian Tiger Chow
de170927ad fix(commands/request) cast safely
should be able to look at a function in isolation and prove it won't
panic. if that's not possible, should cast safely.
2014-11-05 10:15:17 -08:00
Brian Tiger Chow
d3f9aadd3e fix(commands/http/client) cast safely 2014-11-05 10:15:17 -08:00
Matt Bell
1b9b60331f commands/http: Cleaned up argument handling in Parse 2014-11-04 02:04:51 -08:00
Matt Bell
db9c7f7c29 commands: Fixed panic when trying to marshal without a command set in request 2014-11-04 02:04:51 -08:00
Matt Bell
df6c700426 commands/http: Renamed variable for clarity 2014-11-04 02:04:51 -08:00
Matt Bell
c8ae4b6f42 commands/http: Decomposed Client#Send function 2014-11-04 02:04:51 -08:00
Matt Bell
e57cd9b857 commands/http: Use net/url querystring encoder 2014-11-04 02:04:51 -08:00
Matt Bell
33b0990a3a commands/http: Cleaner URL formation in client 2014-11-04 02:04:51 -08:00
Matt Bell
5e5d534eb3 commands/http: Refactored API to a Client object that takes a string address 2014-11-04 02:04:50 -08:00
Matt Bell
2a1116cec8 commands: Allow overriding marshaller for any encoding type 2014-11-04 02:04:50 -08:00
Matt Bell
33ad56e6d0 commands: Safer type coercion when choosing marshaller 2014-11-04 02:04:50 -08:00
Matt Bell
0149f65c6c commands: Replaced 'Formatter' with 'Marshaller' 2014-11-04 02:04:50 -08:00
Matt Bell
068e10cc5d commands/cli: Better comment for parsePath 2014-11-04 02:04:50 -08:00
Matt Bell
958e524c1e commands: Nicer syntax for Argument definition 2014-11-04 02:04:50 -08:00
Matt Bell
f76048f74b commands/http: Unexported Handler fields and created constructor 2014-11-04 02:04:50 -08:00
Matt Bell
4552fce517 commands/http: Respond with error if encoding option isn't a string 2014-11-04 02:04:50 -08:00
Matt Bell
446acdcdb5 commands/http: Ensure request URLs start with expected prefix 2014-11-04 02:04:50 -08:00
Matt Bell
bc6938dc08 commands: Cleaned up argument validation 2014-11-04 02:04:49 -08:00
Matt Bell
f6c38882f0 commands: Return a reader in a Response#Reader method, instead of making Response implementing io.Reader 2014-11-04 02:04:49 -08:00
Matt Bell
69a56de040 commands: Renamed Response#Value to Response#Output 2014-11-04 02:04:49 -08:00
Matt Bell
75649f3d49 commands: Moved argument checking into a Command method, fail early when parsing commands 2014-11-04 02:04:49 -08:00
Matt Bell
dbeffb6a0b commands: CLI Parse: Don't parse args until after creating request 2014-11-04 02:04:49 -08:00
Matt Bell
586a019fbf commands: Fixed Request#CheckArguments not erroring when required arguments were missing 2014-11-04 02:04:49 -08:00
Matt Bell
405cfd9762 commands/http: Made parser/client handle variadic arguments 2014-11-04 02:04:49 -08:00
Matt Bell
2c8fc8564c commands/cli: Made parser handle variadic arguments 2014-11-04 02:04:49 -08:00
Matt Bell
e8d0cbff1d commands: Check argument validity when running commands 2014-11-04 02:04:49 -08:00
Matt Bell
ee2c76992a commands/cli: Open argument files when creating Requests (Moved out of HTTP client) 2014-11-04 02:04:48 -08:00
Matt Bell
f7aa2b9f10 commands: Renamed ArgPath to ArgFile 2014-11-04 02:04:48 -08:00
Matt Bell
40858b43ed commands/http: Added stream argument handling to client and request parser 2014-11-04 02:04:48 -08:00
Matt Bell
39c78fbe06 commands: Fixed tests 2014-11-04 02:04:48 -08:00
Matt Bell
3a8d60cc61 commands: Removed inpout stream from Request 2014-11-04 02:04:48 -08:00
Matt Bell
827f1dd0b0 commands: Changed Request arguments to a []interface{} 2014-11-04 02:04:48 -08:00
Matt Bell
30e968754e commands/cli: Error if no subcommand matched 2014-11-04 02:04:48 -08:00
Matt Bell
83b2ba00e9 commands: Removed Command#Private field 2014-11-04 02:04:48 -08:00
Matt Bell
c0d3edd4f9 commands/cli: Made Parse handle multiple root commands 2014-11-04 02:04:47 -08:00
Matt Bell
cfa56dde82 commands/http: Error if trying to run private command 2014-11-04 02:04:47 -08:00
Matt Bell
abcebb0bc2 commands/http: Improved client error handling 2014-11-04 02:04:47 -08:00
Matt Bell
ea09268044 commands/http: 404 when trying to call root command 2014-11-04 02:04:47 -08:00
Matt Bell
1e0cabd4db commands/http: Pass root command in as field instead of statically depending on core/commands 2014-11-04 02:04:47 -08:00
Matt Bell
460387fc3b commands: Added 'Private' field to Command 2014-11-04 02:04:47 -08:00
Matt Bell
b61cfd9224 commands: Don't error when marshalling empty Responses 2014-11-04 02:04:47 -08:00
Brian Tiger Chow
4911dc069a refactor(commands) swap argument order to match Http(w, r) idiom 2014-11-04 02:04:47 -08:00
Brian Tiger Chow
b1bf60b877 fix(cmd/ipfs2, commands) imports 2014-11-04 02:04:46 -08:00
Matt Bell
c0a9871d48 commands/http: Made HTTP client unmarshal response values based on the Command#Type 2014-11-04 02:04:46 -08:00
Matt Bell
ef290faa88 commands: Added a Type field for defining output struct formats 2014-11-04 02:04:46 -08:00
Matt Bell
6302356e15 commands: Fixed tests 2014-11-04 02:04:46 -08:00
Matt Bell
32a2959348 commands/http: Don't try to parse HTTP response into a Response, just read the output 2014-11-04 02:04:46 -08:00
Matt Bell
714e13b63a commands/http: Explicitly define the MIME types for each encoding 2014-11-04 02:04:46 -08:00
Matt Bell
b54801cc10 commands: Added plaintext marshalling to Response#Marshal() 2014-11-04 02:04:46 -08:00
Matt Bell
38f8f1c279 commands: Added a Format function to Command, for creating human-readable output based on a Response 2014-11-04 02:04:46 -08:00
Matt Bell
81f29257a1 commands: Gave Requests a reference to the command they are being called on 2014-11-04 02:04:46 -08:00
Matt Bell
507192ef6e commands/http: Use request body as command input stream 2014-11-04 02:04:45 -08:00
Matt Bell
42633e5d40 commands/http: Send request arguments in client requests 2014-11-04 02:04:45 -08:00
Matt Bell
753162529a commands/http: Parse command args 2014-11-04 02:04:45 -08:00
Matt Bell
52bc8bd422 commands/http: Moved http request parsing into a Parse function 2014-11-04 02:04:45 -08:00
Matt Bell
29b96b64a5 commands/http: Made Handler set request contexts 2014-11-04 02:04:45 -08:00
Matt Bell
289bce6bdb commands: Added Request#SetContext() 2014-11-04 02:04:45 -08:00
Matt Bell
48bd73c530 commands/http: Made client load RPC host from config 2014-11-04 02:04:45 -08:00
Matt Bell
20f86c01ce commands: Added Context() to Request 2014-11-04 02:04:45 -08:00
Matt Bell
b033e33293 commands: Fixed test 2014-11-04 02:04:44 -08:00
Matt Bell
53e1359871 commands: Silently skip unrecognized options, it should be up to the transport to decide if they cause an error 2014-11-04 02:04:44 -08:00
Matt Bell
43c61a4e4b commands/http: Moved HTTP RPC handler into commands/http 2014-11-04 02:04:44 -08:00
Matt Bell
8b61daa1db commands/http: Moved HTTP RPC into commands/http package 2014-11-04 02:04:44 -08:00
Matt Bell
a65c99e71e commands: Added Request#Options so consumers can iterate through provided options 2014-11-04 02:04:44 -08:00
Matt Bell
e8b37acda3 commands: Simplified Error string output 2014-11-04 02:04:44 -08:00
Matt Bell
3cebd2176e commands: Made Response implement io.Reader 2014-11-04 02:04:44 -08:00
Matt Bell
94683bb6b2 commands: Removed unused output stream field from Response 2014-11-04 02:04:43 -08:00
Matt Bell
19e5fbae70 commands: Made Response#Error return an *Error instead of an error 2014-11-04 02:04:43 -08:00
Juan Batiz-Benet
184c25430b go-vet friendly codebase
- distinguish log.Error and log.Errorf functions
- Initialize structs with field names
- A bit of unreachable code (defers)
2014-10-25 03:46:39 -07:00
Matt Bell
4303dccee9 commands: Added Request#SetStream 2014-10-21 18:27:39 -07:00
Matt Bell
12a6a87b2c commands/cli: Made Parse return a Request (again) 2014-10-21 18:27:05 -07:00