marqdo

Mid stdlib — lists and cliok

features/12-list-cli.mq.md

文档

table:lib/table.mq.mdcsv:lib/csv.mq.mdcli: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 =nameaccess(`r0`, "name")
args = > split value="--input,scores.csv,--pretty" sep=","
flags = > cli.parse args=`args`
> print text =inputaccess(`flags`, "input")
  1. [pretty](access(flags, "pretty"))
    > print text=mid-m5-ok
  2. else
    > print text=mid-m5-fail
Functions
Variables
  • args list · 3
    #value
    1--input
    2scores.csv
    3--pretty
  • description text
    table sort/unique/zip + cli.parse (Mid M5)
  • flags map · 2
    inputscores.csv
    prettyTrue
  • markup text
    occlusion
  • r0 map · 2
    namealice
    score10
  • raw text
    name,score bob,2 alice,10
  • rows list · 2
    #namescore
    1alice10
    2bob2
  • title text
    Mid stdlib — lists and cli
可执行知识(辅助)

运行与结果

alice scores.csv mid-m5-ok
完整源码
---
markup: occlusion
title: Mid stdlib — lists and cli
description: table sort/unique/zip + cli.parse (Mid M5)
import:
  table: lib/table.mq.md
  csv: lib/csv.mq.md
  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](access(`r0`, "name"))

**args = > split value="--input,scores.csv,--pretty" sep=","**
**flags = > cli.parse args=`args`**
> print text=[input](access(`flags`, "input"))
1. [pretty](access(`flags`, "pretty"))
  > print text=mid-m5-ok
2. *
  > print text=mid-m5-fail

Variable