Slide 1

Slide 1 text

BUILDING COMMAND LINE INTERFACES IN Node.JS 1 Copyright © 2012 Clock Limited Clock ® is a registered trademark of Clock limited in the EU and other territories Registered in England and Wales No.3457724 VAT Registered No. 706 7654 20

Slide 2

Slide 2 text

@domharrington 2 WHO AM I? Github: domharrington

Slide 3

Slide 3 text

'process' module Arguments accessible via 'process.argv' Array of arguments 3 COMMAND- LINE IN NODE

Slide 4

Slide 4 text

4

Slide 5

Slide 5 text

Perfectly fine if you only need one argument E.g. accessing the first argument: process.argv[2] Parsing of options becomes unmanageable 5 PROBLEMS WITH THIS APPROACH

Slide 6

Slide 6 text

Module to help ease the pain of parsing command-line options Simple, natural API Auto generated --help and --version 6 COMMANDER.JS https://github.com/visionmedia/commander.js/

Slide 7

Slide 7 text

7

Slide 8

Slide 8 text

8

Slide 9

Slide 9 text

Options don't need to be defined All options are parsed automatically Also has default values, aliases Many more features 9 NODE-OPTIMIST https://github.com/substack/node-optimist

Slide 10

Slide 10 text

10

Slide 11

Slide 11 text

11

Slide 12

Slide 12 text

aparser cli node-arguments And many more … 12 SOME MORE LIBRARIES

Slide 13

Slide 13 text

13 WHERE HAVE I USED IT? https://github.com/domharrington/gitme

Slide 14

Slide 14 text

14 ANY QUESTIONS?