In this chapter, we'll take a look at developing command-line server-side apps. In particular, we'll learn the following topics:
args
packagedart:io
librarysqljocky
packageroute
packageThis chapter assumes that you already have at least basic experience with CLI scripts or Unix environments in general. If you're a Windows user, take a look at Cygwin (www.cygwin.com), which is a Unix-like environment for Windows, or ideally, install Ubuntu into a virtual machine. The Dart SDK is now available for Debian and Ubuntu Linux distributions, while Dart Editor is currently available only for Ubuntu Linux.
We'll set off with a few notes about Dart VM and then go to processing command-line arguments, because that's what you'll probably use every time you start developing a CLI app.
The Dart SDK comes with a standalone Dart VM to run command-line apps such as pub
or dart2js
. You can find it in <dart-sdk-dir>/bin/dart
. It accepts command-line arguments such as -h
for help or -c
to enable the checked mode. There are also special options for the Observatory tool (we'll use it in Chapter 8, Testing and Profiling the Dart Code). These aren't very interesting for us now, but feel free to check out https://www.dartlang.org/tools/dart-vm/ for a complete list of all supported options.
The standalone Dart VM is mostly the same environment as the VM implemented in the Dartium browser. The entry point for an app is a top-level main()
function, but this time, it accepts a list of arguments passed from the command line:
main(List<String> args) { /* ... */ }
With the standalone Dart VM, you can't use libraries specific to the browser environment, such as dart:html
, of course. On the other hand, you can use dart:io
to access the filesystem or create subprocesses, listen to signals, and so on. We're going to use this package a lot in this chapter.
18.191.144.65