Considerations When Creating a Command Line Interface

There are many best GUI practices. I am looking for best practices when developing a command line.

For example, if I create a backup program, which is better?

Consideration 1, challenge:

backup program.exe

program.exe / backup

program.exe -backup

program.exe --backup

Consideration 2, parameters:

program.exe backup "C: \ file1.txt" "C: \ file1.bak" (implicit source and destination)

program.exe backup -source "C: \ file1.txt" -destination "C: \ file1.bak" (explicit)

program.exe backup -source "C: \ file1.txt" "C: \ file2.txt" "C: \ file3.txt" -destination "C: \ files.bak" (multiple sources)

program.exe backup -source "C:\file1.txt" -source "C:\file2.txt" -source "C:\file3.txt" -destination "C:\files.bak" ( , )

3, :

program.exe backup "C:\file1.txt" "C:\file1.bak" backup "C:\file2.txt" "C:\file2.bak" ( ?)

4, :

program.exe

program.exe bkp

program.exe b ( ?)

+3
7

, ( ):

, Windows / ( ), /source /destination ( ) , , :

program.exe/backup/source: "c:\source" /destination: "c:\destination"

, , :

program.exe/b/s: "c:\source" /d: "c:\destination"

, . , /?, . , , /?, - . , CLI :

v1.01

, /?

, , , : . , ( # Windows). , - .

+2

.

- , , .

, , :

  program.exe --backup   
  program.exe -b 

:

  program.exe --restore "5/6/2010"
  program.exe -r "5/6/2010"

:

  program.exe --help
  program.exe -h
+1

/Help . , , ,

+1
  • --long-option-name -lon .
  • backup.exe backup program.exe.
  • .
  • .

UNIX/Linux. Windows .

  • /source /destination. , , cp (copy) .
+1

, . , Microsoft Windows ! . , dd:

dd if=C:\file1.txt of=C:\file2.bak

.

+1

program.exe backup.exe

/option:<value>. :

backup /d:"c:\mydirectory" /o:"c:\mybackup.bak"
backup /f:"c:\mydiredctory\myfile.txt" /o:"c:\mybackup.bak"
backup /f:"mydiredctory\myfile.txt,mydiredctory\myfile2.txt" /o:"c:\mybackup.bak"
0

I recommend finding a library that allows you to determine command line parameters and analyze them correctly, as well as print usage instructions that define all your parameters for users of your application. Multiple open source libraries should be available for multiple languages ​​and platforms.

0
source

Source: https://habr.com/ru/post/1763104/


All Articles