12-list-cliok
Structure
importtable:lib/table.mq.mdcsv:lib/csv.mq.mdcli:lib/cli.mq.md
fn · h1Sort CSV rows and parse flags
comment
fn · h1main
bind
`raw` = name,score
bob,2
alice,10
bind
`rows` = > csv.parse text=`raw`bind
`rows` = > table.sort_by list=`rows` key=namebind
`r0` = > at value=`rows` index=0call
> print text=[name](`r0`)bind
`args` = > split value=--input,scores.csv,--pretty sep=,bind
`flags` = > cli.parse args=`args`call
> print text=[input](`flags`)branch
arm
[pretty](`flags`)call
> print text=mid-m5-okarm
elsecall
> print text=mid-m5-failFunctions
Variables
-
args list · 3
# value 1 --input 2 scores.csv 3 --pretty # value 1 --input 2 scores.csv 3 --pretty -
flags map · 2
input scores.csv pretty True key value input scores.csv pretty True -
r0 map · 2
name alice score 10 key value name alice score 10 -
raw textname,score bob,2 alice,10name,score bob,2 alice,10
-
rows list · 2
# name score 1 alice 10 2 bob 2 # name score 1 alice 10 2 bob 2
Execution
alice
scores.csv
mid-m5-ok
Source
--- title: Mid stdlib — lists and cli description: table sort/unique/zip + cli.parse (Mid M5) import table:lib/table.mq.md import csv:lib/csv.mq.md import cli:lib/cli.mq.md --- # Sort CSV rows and parse flags Zero plugins: parse CSV, sort by key, parse `--input`. # main **raw = "name,score\nbob,2\nalice,10\n"** **rows = > csv.parse text=`raw`** **rows = > table.sort_by list=`rows` key="name"** **r0 = > at value=`rows` index=0** > print text=[name](`r0`) **args = > split value="--input,scores.csv,--pretty" sep=","** **flags = > cli.parse args=`args`** > print text=[input](`flags`) 1. [pretty](`flags`) > print text=mid-m5-ok 2. * > print text=mid-m5-fail
Zero plugins: parse CSV, sort by key, parse
--input.