Skip to content

Writing Your Own AFib Commands

You can create subcommands that appear as part of your dart bin/xxx_afib.dart command. For example, in the app that spawned AFib, we have commands that connect to a learning database and export static dart data structures that summarize some of the learned data.

Generating a Custom Command

AFib provides a generate command variant. The command:

dart bin/xxx_afib.dart generate command helloworld

Will generate a command file in:

lib/command/helloworld_command.dart

The new subcommands, prefixed with your project code and a colon:

dart bin/xxx_afib.dart xxx:helloworld
dart bin/xxx_afib.dart help xxx:helloworld

Will immediately be available. By default, they print messages. You can open the command file and use the comments within it for help parsing arguments, validating then, and executing.

Generating Code from a Command

AFib has a lot of existing functionality associated with generating code. This functionality is not currently richly documented, but if you wish to reuse it (for example, to generate code containing static datastructures associated with some kind of machine learning), it would be best to start by looking at the file af_generate_state_command.dart in AFib's own source.