UCDavisLibrary / fin-cli

CLI interface for a Linked Data Platform (Like fin-server)
MIT License
0 stars 0 forks source link

fin common command line options #6

Open qjhart opened 6 years ago

qjhart commented 6 years ago

## Configuration options

The predominant use of the `fin` command will be with an associated configuration file that maintains the user's default values for some global configuration.  These are updated via the `fin config` command.  However, there are times when commands may be run without a configuration file, and so these configuration parameters can be included on the command line as well.

``` {javascript}
command('fin  cmd <options>','Shell and interactive processing')
.option('--jwt <jwt_token>','Specify a connection token'
.option('--host <host>','')
.option('--base <fedora_base>','')
.option('--(no-)config'),'')
.option('--check-status','Replicate HTTPIE, and fail on error codes [345]##')

Command control options.

command('fin  cmd <options>')
.option('--check-status','Replicate HTTPIE, and fail on error codes [345]##')

--check-status

Usually fin responds without error as long as the http request was sent and acknowledged. Setting the --check-status however, will have the command error out with certain http response codes. The exit status is inspired by the httpie command. fin to exits with an error if the HTTP status is one of 3xx, 4xx, or 5xx. The exit status will be 3, 4, or 5, respectively.

#!/bin/bash
if fin httpd head --check-status --base=http://dams.org/fcrepo/rest .  &> /dev/null; then
    echo 'OK!'
else
    case $? in
        2) echo 'Request timed out!' ;;
        3) echo 'Unexpected HTTP 3xx Redirection!' ;;
        4) echo 'HTTP 4xx Client Error!' ;;
        5) echo 'HTTP 5xx Server Error!' ;;
        *) echo 'Other Error!' ;;
    esac
fi

http request options

The following options effect the request headers and response format for the commands. These are avialable in every http command, and those commands which accept user defined headers. The print command also allows the user to see the raw http requests and/or responses (though there may be multiple ones for some commands)

command('fin [command] [sub-command] <path>')
.option('-H --header <header>','Add additional Headers to the request')
.option('-P --print <print>','Specify what components to print to user')

--header

This allows any header to be added to a core command. Note this command can be included on any other fin-cli command, unless otherwise specified.

# Set the format for your output
fin http get  -H 'Accept: application/rdf+xml'  ./

--print

This allows users to identify what components of the communication they would like to see. This follows the httpie convention where the value is any combination of 'hbHB' where:

The default value is the value of config.print or print=hb for the http sub-commands if not specified. Individual commands can overwrite the default value, or the config.print value, but not any value specified in by an explicit --print option. The order of display is HBhb and they are separated by an empty line.