github.com/henvic/wedeploycli@v1.7.6-0.20200319005353-3630f582f284/command/curl/internal/curlargs/curlargs.go (about)

     1  package curlargs
     2  
     3  import "strings"
     4  
     5  // See https://github.com/curl/curl/blob/master/src/tool_getparam.c
     6  // Last synchronization:
     7  // commit c45360d4633850839bb9c2d77dbf8a8285e9ad49
     8  // date: 11, June 2018.
     9  
    10  // curl uses three types of parameters:
    11  // stand-alone but not a boolean, bool (accepts a --no-[name] prefix), and string
    12  
    13  // IsCLIStringArgument tells if the command is a cURL CLI string argument
    14  func IsCLIStringArgument(a string) bool {
    15  	for _, alias := range Aliases {
    16  		if a == "-"+alias.Letter || a == "--"+alias.Name {
    17  			return alias.Type == String
    18  		}
    19  	}
    20  
    21  	return false
    22  }
    23  
    24  // IsCLIArgument tells if the command is a cURL CLI argument
    25  func IsCLIArgument(a string) bool {
    26  	if strings.HasPrefix(a, "-X") {
    27  		return true
    28  	}
    29  
    30  	for _, alias := range Aliases {
    31  		if a == "-"+alias.Letter || a == "--"+alias.Name {
    32  			return true
    33  		}
    34  	}
    35  
    36  	return false
    37  }
    38  
    39  // Argument of the curl CLI tool
    40  type Argument int
    41  
    42  const (
    43  	// None means curl accepts no argument parameter
    44  	None Argument = iota
    45  	// Bool means curl accepts either --[name] or --no-[name]
    46  	Bool
    47  	// String means curl accepts a string as parameter for the given argument
    48  	String
    49  )
    50  
    51  // LongShort is a description of each option curl accepts
    52  type LongShort struct {
    53  	Letter string
    54  	Name   string
    55  	Type   Argument
    56  }
    57  
    58  // Aliases is the list of options curl accepts
    59  var Aliases = []LongShort{
    60  	/* 'letter' strings with more than one character have *no* short option to
    61  	   mention. */
    62  	{"*@", "url", String},
    63  	{"*4", "dns-ipv4-addr", String},
    64  	{"*6", "dns-ipv6-addr", String},
    65  	{"*a", "random-file", String},
    66  	{"*b", "egd-file", String},
    67  	{"*B", "oauth2-bearer", String},
    68  	{"*c", "connect-timeout", String},
    69  	{"*d", "ciphers", String},
    70  	{"*D", "dns-interface", String},
    71  	{"*e", "disable-epsv", Bool},
    72  	{"*f", "disallow-username-in-url", Bool},
    73  	{"*E", "epsv", Bool},
    74  	/* 'epsv' made like this to make --no-epsv and --epsv to work
    75  	   although --disable-epsv is the documented option */
    76  	{"*F", "dns-servers", String},
    77  	{"*g", "trace", String},
    78  	{"*G", "npn", Bool},
    79  	{"*h", "trace-ascii", String},
    80  	{"*H", "alpn", Bool},
    81  	{"*i", "limit-rate", String},
    82  	{"*j", "compressed", Bool},
    83  	{"*J", "tr-encoding", Bool},
    84  	{"*k", "digest", Bool},
    85  	{"*l", "negotiate", Bool},
    86  	{"*m", "ntlm", Bool},
    87  	{"*M", "ntlm-wb", Bool},
    88  	{"*n", "basic", Bool},
    89  	{"*o", "anyauth", Bool},
    90  	{"*p", "wdebug", Bool},
    91  	{"*q", "ftp-create-dirs", Bool},
    92  	{"*r", "create-dirs", Bool},
    93  	{"*s", "max-redirs", String},
    94  	{"*t", "proxy-ntlm", Bool},
    95  	{"*u", "crlf", Bool},
    96  	{"*v", "stderr", String},
    97  	{"*w", "interface", String},
    98  	{"*x", "krb", String},
    99  	{"*x", "krb4", String},
   100  	/* 'krb4' is the previous name */
   101  	{"*X", "haproxy-protocol", Bool},
   102  	{"*y", "max-filesize", String},
   103  	{"*z", "disable-eprt", Bool},
   104  	{"*Z", "eprt", Bool},
   105  	/* 'eprt' made like this to make --no-eprt and --eprt to work
   106  	   although --disable-eprt is the documented option */
   107  	{"*~", "xattr", Bool},
   108  	{"$a", "ftp-ssl", Bool},
   109  	/* 'ftp-ssl' deprecated name since 7.20.0 */
   110  	{"$a", "ssl", Bool},
   111  	/* 'ssl' new option name in 7.20.0, previously this was ftp-ssl */
   112  	{"$b", "ftp-pasv", Bool},
   113  	{"$c", "socks5", String},
   114  	{"$d", "tcp-nodelay", Bool},
   115  	{"$e", "proxy-digest", Bool},
   116  	{"$f", "proxy-basic", Bool},
   117  	{"$g", "retry", String},
   118  	{"$V", "retry-connrefused", Bool},
   119  	{"$h", "retry-delay", String},
   120  	{"$i", "retry-max-time", String},
   121  	{"$k", "proxy-negotiate", Bool},
   122  	{"$m", "ftp-account", String},
   123  	{"$n", "proxy-anyauth", Bool},
   124  	{"$o", "trace-time", Bool},
   125  	{"$p", "ignore-content-length", Bool},
   126  	{"$q", "ftp-skip-pasv-ip", Bool},
   127  	{"$r", "ftp-method", String},
   128  	{"$s", "local-port", String},
   129  	{"$t", "socks4", String},
   130  	{"$T", "socks4a", String},
   131  	{"$u", "ftp-alternative-to-user", String},
   132  	{"$v", "ftp-ssl-reqd", Bool},
   133  	/* 'ftp-ssl-reqd' deprecated name since 7.20.0 */
   134  	{"$v", "ssl-reqd", Bool},
   135  	/* 'ssl-reqd' new in 7.20.0, previously this was ftp-ssl-reqd */
   136  	{"$w", "sessionid", Bool},
   137  	/* 'sessionid' listed as --no-sessionid in the help */
   138  	{"$x", "ftp-ssl-control", Bool},
   139  	{"$y", "ftp-ssl-ccc", Bool},
   140  	{"$j", "ftp-ssl-ccc-mode", String},
   141  	{"$z", "libcurl", String},
   142  	{"$#", "raw", Bool},
   143  	{"$0", "post301", Bool},
   144  	{"$1", "keepalive", Bool},
   145  	/* 'keepalive' listed as --no-keepalive in the help */
   146  	{"$2", "socks5-hostname", String},
   147  	{"$3", "keepalive-time", String},
   148  	{"$4", "post302", Bool},
   149  	{"$5", "noproxy", String},
   150  	{"$7", "socks5-gssapi-nec", Bool},
   151  	{"$8", "proxy1.0", String},
   152  	{"$9", "tftp-blksize", String},
   153  	{"$A", "mail-from", String},
   154  	{"$B", "mail-rcpt", String},
   155  	{"$C", "ftp-pret", Bool},
   156  	{"$D", "proto", String},
   157  	{"$E", "proto-redir", String},
   158  	{"$F", "resolve", String},
   159  	{"$G", "delegation", String},
   160  	{"$H", "mail-auth", String},
   161  	{"$I", "post303", Bool},
   162  	{"$J", "metalink", Bool},
   163  	{"$K", "sasl-ir", Bool},
   164  	{"$L", "test-event", Bool},
   165  	{"$M", "unix-socket", String},
   166  	{"$N", "path-as-is", Bool},
   167  	{"$O", "socks5-gssapi-service", String},
   168  	/* 'socks5-gssapi-service' merged with'proxy-service-name' and
   169  	   deprecated since 7.49.0 */
   170  	{"$O", "proxy-service-name", String},
   171  	{"$P", "service-name", String},
   172  	{"$Q", "proto-default", String},
   173  	{"$R", "expect100-timeout", String},
   174  	{"$S", "tftp-no-options", Bool},
   175  	{"$U", "connect-to", String},
   176  	{"$W", "abstract-unix-socket", String},
   177  	{"$X", "tls-max", String},
   178  	{"$Y", "suppress-connect-headers", Bool},
   179  	{"$Z", "compressed-ssh", Bool},
   180  	{"$~", "happy-eyeballs-timeout-ms", String},
   181  	{"0", "http1.0", None},
   182  	{"01", "http1.1", None},
   183  	{"02", "http2", None},
   184  	{"03", "http2-prior-knowledge", None},
   185  	{"1", "tlsv1", None},
   186  	{"10", "tlsv1.0", None},
   187  	{"11", "tlsv1.1", None},
   188  	{"12", "tlsv1.2", None},
   189  	{"13", "tlsv1.3", None},
   190  	{"1A", "tls13-ciphers", String},
   191  	{"1B", "proxy-tls13-ciphers", String},
   192  	{"2", "sslv2", None},
   193  	{"3", "sslv3", None},
   194  	{"4", "ipv4", None},
   195  	{"6", "ipv6", None},
   196  	{"a", "append", Bool},
   197  	{"A", "user-agent", String},
   198  	{"b", "cookie", String},
   199  	{"B", "use-ascii", Bool},
   200  	{"c", "cookie-jar", String},
   201  	{"C", "continue-at", String},
   202  	{"d", "data", String},
   203  	{"dr", "data-raw", String},
   204  	{"da", "data-ascii", String},
   205  	{"db", "data-binary", String},
   206  	{"de", "data-urlencode", String},
   207  	{"D", "dump-header", String},
   208  	{"e", "referer", String},
   209  	{"E", "cert", String},
   210  	{"Ea", "cacert", String},
   211  	{"Eb", "cert-type", String},
   212  	{"Ec", "key", String},
   213  	{"Ed", "key-type", String},
   214  	{"Ee", "pass", String},
   215  	{"Ef", "engine", String},
   216  	{"Eg", "capath", String},
   217  	{"Eh", "pubkey", String},
   218  	{"Ei", "hostpubmd5", String},
   219  	{"Ej", "crlfile", String},
   220  	{"Ek", "tlsuser", String},
   221  	{"El", "tlspassword", String},
   222  	{"Em", "tlsauthtype", String},
   223  	{"En", "ssl-allow-beast", Bool},
   224  	{"Eo", "login-options", String},
   225  	{"Ep", "pinnedpubkey", String},
   226  	{"EP", "proxy-pinnedpubkey", String},
   227  	{"Eq", "cert-status", Bool},
   228  	{"Er", "false-start", Bool},
   229  	{"Es", "ssl-no-revoke", Bool},
   230  	{"Et", "tcp-fastopen", Bool},
   231  	{"Eu", "proxy-tlsuser", String},
   232  	{"Ev", "proxy-tlspassword", String},
   233  	{"Ew", "proxy-tlsauthtype", String},
   234  	{"Ex", "proxy-cert", String},
   235  	{"Ey", "proxy-cert-type", String},
   236  	{"Ez", "proxy-key", String},
   237  	{"E0", "proxy-key-type", String},
   238  	{"E1", "proxy-pass", String},
   239  	{"E2", "proxy-ciphers", String},
   240  	{"E3", "proxy-crlfile", String},
   241  	{"E4", "proxy-ssl-allow-beast", Bool},
   242  	{"E5", "login-options", String},
   243  	{"E6", "proxy-cacert", String},
   244  	{"E7", "proxy-capath", String},
   245  	{"E8", "proxy-insecure", Bool},
   246  	{"E9", "proxy-tlsv1", None},
   247  	{"EA", "socks5-basic", Bool},
   248  	{"EB", "socks5-gssapi", Bool},
   249  	{"f", "fail", Bool},
   250  	{"fa", "fail-early", Bool},
   251  	{"fb", "styled-output", Bool},
   252  	{"F", "form", String},
   253  	{"Fs", "form-string", String},
   254  	{"g", "globoff", Bool},
   255  	{"G", "get", None},
   256  	{"Ga", "request-target", String},
   257  	{"h", "help", Bool},
   258  	{"H", "header", String},
   259  	{"Hp", "proxy-header", String},
   260  	{"i", "include", Bool},
   261  	{"I", "head", Bool},
   262  	{"j", "junk-session-cookies", Bool},
   263  	{"J", "remote-header-name", Bool},
   264  	{"k", "insecure", Bool},
   265  	{"K", "config", String},
   266  	{"l", "list-only", Bool},
   267  	{"L", "location", Bool},
   268  	{"Lt", "location-trusted", Bool},
   269  	{"m", "max-time", String},
   270  	{"M", "manual", Bool},
   271  	{"n", "netrc", Bool},
   272  	{"no", "netrc-optional", Bool},
   273  	{"ne", "netrc-file", String},
   274  	{"N", "buffer", Bool},
   275  	/* 'buffer' listed as --no-buffer in the help */
   276  	{"o", "output", String},
   277  	{"O", "remote-name", None},
   278  	{"Oa", "remote-name-all", Bool},
   279  	{"p", "proxytunnel", Bool},
   280  	{"P", "ftp-port", String},
   281  	{"q", "disable", Bool},
   282  	{"Q", "quote", String},
   283  	{"r", "range", String},
   284  	{"R", "remote-time", Bool},
   285  	{"s", "silent", Bool},
   286  	{"S", "show-error", Bool},
   287  	{"t", "telnet-option", String},
   288  	{"T", "upload-file", String},
   289  	{"u", "user", String},
   290  	{"U", "proxy-user", String},
   291  	{"v", "verbose", Bool},
   292  	{"V", "version", Bool},
   293  	{"w", "write-out", String},
   294  	{"x", "proxy", String},
   295  	{"xa", "preproxy", String},
   296  	{"X", "request", String},
   297  	{"Y", "speed-limit", String},
   298  	{"y", "speed-time", String},
   299  	{"z", "time-cond", String},
   300  	{"#", "progress-bar", Bool},
   301  	{":", "next", None},
   302  }