Closed Steve0Greatness closed 1 year ago
Could you give an example of what this would output? Never mind, I think I've got it.
I have a few problems with this:
gleam_javascript
for mutability, it isn't needed.Overall, I think this is a good idea, but the implementation would have to change before it is merged.
Here is an alternative:
const usage = [
#("create <name>", "Create a new project"),
#("run", "Run the current project"),
#("<path>", "Run the given file"),
]
pub fn main() {
case utils.get_args(), get_project() {
_, #(True, Error(msg)) -> error(msg)
["create", name, ..], _ -> create_project(name)
["run", ..], #(True, Ok(project)) -> run_project(project.name)
[path, ..], _ -> run_file(path)
_, _ -> print_usage()
}
}
fn print_usage() -> Nil {
let assert Ok(max_len) =
usage
|> list.map(fn(x) { string.length(x.0) })
|> list.sort(int.compare)
|> list.last
io.println("Usage:")
usage
|> list.each(fn(x) {
let #(command, desc) = x
let left_over = max_len - string.length(command) + 2
io.println(" bella " <> command <> string.repeat(" ", left_over) <> desc)
})
}
Output:
Usage:
bella create <name> Create a new project
bella run Run the current project
bella <path> Run the given file
Do you mind if I use this instead?
Sure.
Reason: grids are cool. Problem with the old way: it's not a grid, and grids are cool.
But really, this automatically adds spaces, meaning if new longer commands are added then all other lines don't need to be re-formatted manually(this would get especially tedious the more commands added).