顯示具有 Command 標籤的文章。 顯示所有文章
顯示具有 Command 標籤的文章。 顯示所有文章

2020年5月10日 星期日

C 語言 - CLI ( Command Line Interface ) 設計 (1)

CLI 命令列介面


    在設計 CLI 的程式時,最好的方法是遵從 IEEE Std 1003 ( POSIX ) 對 program 的 command-line options 之規範。所以用 getopt 去做 parse command-line 是最簡單的,有一點要注意的是 GNU 提供的 getopt 支援 " -- ",這個 POSIX 沒有規範。

常見的 Usage 設計

    Usage : 
        my_program tcp <host> <port> [--timeout=<seconds>]
        my_program serial <port> [--baud=9600] [--timeout=<seconds>]
        my_program (-h | --help)
    參數
    my_program   : program name
    tcp   : commands
    -h, --help   : options
    <host>   : arguments

    符號
    [ ]   : optional
    ( )   :  required
     |   :  mutually exclusive
    ...   :  repeating elements

Options 設計


    在設計長命名的 option ( " -- " ),最好需要有一個相對短命名的 option ( " - " ),example : -h, --help。

    每隻程式最好都要有 --help 跟 --version


參考資料 :

2019年11月5日 星期二

Windows Command Line

CMD : Command Line

列出檔案

     dir                            // 列出當前資料夾下的檔案
     dir /s                         // 列出當前資料夾下 + 子資料夾的檔案
     dir /?                         // 列出所有 dir 的指令參數

輸出成檔案

     dir /? > 123.txt               // 輸出成 123.txt

檔案名稱有空格

     net share "共用 資料夾名稱"     // 用雙引號,不能用單引號

參考資料 : 1. https://www.csie.ntu.edu.tw/~r91112/myDownload/WEB/CMD.html
                   2. https://www.itread01.com/content/1543219938.html

Popular Posts