Skip to content

Commit

Permalink
Use optparse.Help for formatting help messages
Browse files Browse the repository at this point in the history
  • Loading branch information
yorickpeterse committed Oct 27, 2023
1 parent 8a3cdb2 commit b5a3978
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
2 changes: 1 addition & 1 deletion inko.pkg
Original file line number Diff line number Diff line change
@@ -1 +1 @@
require https://github.com/yorickpeterse/inko-optparse 0.1.0 086e566cde16aa28c252fe28b618a18585f003ea
require https://github.com/yorickpeterse/inko-optparse 0.2.0 580f7344f7a6227fe48c330b69dc708ac96f7e83
30 changes: 21 additions & 9 deletions src/main.inko
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,26 @@ import openflow.metrics.Metrics
import openflow.more_sense.MoreSense
import openflow.state.(Room, State, Status)
import openflow.sync.Waiter
import optparse.Options
import optparse.(Help, Options)
import std.env
import std.process.(sleep)
import std.stdio.(STDERR, STDOUT)
import std.sys.(exit)
import std.time.Duration

let DEFAULT_CONFIG = '/etc/openflow.json'
let USAGE = 'Usage: openflow [OPTIONS]

Examples:

openflow # Start using the default configuration file
openflow --config config.json # Use ./config.json as the configuration file'

class async Main {
fn async main {
let opts = Options.new

opts.flag('h', 'help', 'Show this help message')
opts.single('c', 'config', 'PATH', 'The configuration file to use')
opts.single(
'c',
'config',
'PATH',
"The configuration file to use (default: {DEFAULT_CONFIG})"
)

let matches = match opts.parse(env.arguments) {
case Ok(matches) -> matches
Expand All @@ -43,7 +42,20 @@ class async Main {
}

if matches.contains?('help') {
STDOUT.new.print("{USAGE}\n\nOptions:\n\n{opts}")
let help = Help
.new('openflow')
.section('Examples')
.line(
'openflow # Start using the default configuration file'
)
.line(
'openflow --config config.json # Use ./config.json as the configuration file'
)
.section('Options')
.options(opts)
.to_string

STDOUT.new.write_string(help)
return
}

Expand Down

0 comments on commit b5a3978

Please sign in to comment.