2017-11-24

Yargs Node.js console apps in F#

Yargs is a Node.js library for parsing command line arguments. In the last month alone, it had more than 45 million downloads from npmjs.com. After importing its TypeScript definition files using ts2fable, you can use it from Fable to build a Node.js app using F#. I just added a yargs template to ctaggart.templates, so that you can easily try it out and get started. Here is a video demo to walk you through it:



Here are some commands you could run to try it out. If you are on a Mac or Linux, just run the commands inside of the PowerShell scripts directly.

started.txt loading ...
Here is the example that I ported from the Yargs documentation and included in the template:

App.fs loading ...

Simple Example

I ported the "simple example" as well, but it got a bit more complicated when you handle all the validation yourself.

SimpleExample.fs loading ...

ts2fable 0.4.0 usage

I just released ts2fable 0.4.0 today after merging in changes for it to use ts2fable. It doesn't yet support any options besides the list of files to work with. For completeness, here is the code I used.

ts2fable-yargs.fs loading ...