import 'package:dcli/dcli.dart';
print("Now let's do someting useful.");
var username = ask( 'username:');
print('username: $username');
var password = ask( 'password:', hidden: true);
print('password: $password');
// Truncate any existing content
// of the file 'tmp/text.txt' and write
// 'Hello world' to the file.
'tmp/text.txt'.write('Hello world');
// append 'My second line' to the file 'tmp/text.txt'.
'tmp/text.txt'.append('My second line');
// and another append to the same file.
'tmp/text.txt'.append('My third line');
// now copy the file tmp/text.txt to second.txt
copy('tmp/text.txt', 'tmp/second.txt', overwrite: true);
// lets dump the file we just created to the console
read('tmp/second.txt').forEach((line) => print(line));
// lets prove that both files exist by running
find('*.txt').forEach((file) => print('Found $file'));
// Now lets tail the file using the OS tail command.
// Again a dart extensions we treat a string
// as an OS command and run that command as
// Stdout and stderr output are written
// directly to the console.
// Lets do a word count capturing stdout,
// stderr will will be swallowed.
'wc tmp/second.txt'.forEach((line) => print('Captured $line'));
if (confirm( "Should I delete 'tmp'? (y/n):")) {
delete('tmp/second.txt');