|
| 1 | +#!/usr/bin/env bash |
| 2 | +# This script was generated by bashly (https://github.com/DannyBen/bashly) |
| 3 | +# Modifying it manually is not recommended |
| 4 | + |
| 5 | +# :command.version_command |
| 6 | +version_command() { |
| 7 | + echo "$version" |
| 8 | +} |
| 9 | + |
| 10 | +# :command.usage |
| 11 | +ftp_usage() { |
| 12 | + if [[ -n $long_usage ]]; then |
| 13 | + echo -e "ftp - Sample application that uses the default command option" |
| 14 | + echo |
| 15 | + else |
| 16 | + echo -e "ftp - Sample application that uses the default command option" |
| 17 | + echo |
| 18 | + fi |
| 19 | + echo -e "Usage:" |
| 20 | + echo -e " ftp [command] [options]" |
| 21 | + echo -e " ftp [command] --help | -h" |
| 22 | + echo -e " ftp --version" |
| 23 | + echo |
| 24 | + # :command.usage_commands |
| 25 | + echo -e "Commands:" |
| 26 | + echo " upload Upload a file (default)" |
| 27 | + echo " download Download a file" |
| 28 | + echo |
| 29 | + |
| 30 | + if [[ -n $long_usage ]]; then |
| 31 | + echo -e "Options:" |
| 32 | + # :command.usage_fixed_flags |
| 33 | + echo " --help, -h" |
| 34 | + echo -e " Show this help" |
| 35 | + echo |
| 36 | + echo " --version" |
| 37 | + echo -e " Show version number" |
| 38 | + echo |
| 39 | + |
| 40 | + fi |
| 41 | +} |
| 42 | + |
| 43 | +# :command.usage |
| 44 | +ftp_upload_usage() { |
| 45 | + if [[ -n $long_usage ]]; then |
| 46 | + echo -e "ftp upload - Upload a file" |
| 47 | + echo |
| 48 | + else |
| 49 | + echo -e "ftp upload - Upload a file" |
| 50 | + echo |
| 51 | + fi |
| 52 | + echo -e "Usage:" |
| 53 | + echo -e " ftp upload SOURCE [options]" |
| 54 | + echo -e " ftp upload --help | -h" |
| 55 | + echo |
| 56 | + |
| 57 | + if [[ -n $long_usage ]]; then |
| 58 | + echo -e "Options:" |
| 59 | + # :command.usage_fixed_flags |
| 60 | + echo " --help, -h" |
| 61 | + echo -e " Show this help" |
| 62 | + echo |
| 63 | + |
| 64 | + # :command.usage_args |
| 65 | + echo -e "Arguments:" |
| 66 | + |
| 67 | + # :argument.usage |
| 68 | + echo " SOURCE" |
| 69 | + echo -e " File to upload" |
| 70 | + echo |
| 71 | + |
| 72 | + fi |
| 73 | +} |
| 74 | + |
| 75 | +# :command.usage |
| 76 | +ftp_download_usage() { |
| 77 | + if [[ -n $long_usage ]]; then |
| 78 | + echo -e "ftp download - Download a file" |
| 79 | + echo |
| 80 | + else |
| 81 | + echo -e "ftp download - Download a file" |
| 82 | + echo |
| 83 | + fi |
| 84 | + echo -e "Usage:" |
| 85 | + echo -e " ftp download SOURCE [options]" |
| 86 | + echo -e " ftp download --help | -h" |
| 87 | + echo |
| 88 | + |
| 89 | + if [[ -n $long_usage ]]; then |
| 90 | + echo -e "Options:" |
| 91 | + # :command.usage_fixed_flags |
| 92 | + echo " --help, -h" |
| 93 | + echo -e " Show this help" |
| 94 | + echo |
| 95 | + |
| 96 | + # :command.usage_args |
| 97 | + echo -e "Arguments:" |
| 98 | + |
| 99 | + # :argument.usage |
| 100 | + echo " SOURCE" |
| 101 | + echo -e " File to download" |
| 102 | + echo |
| 103 | + |
| 104 | + fi |
| 105 | +} |
| 106 | + |
| 107 | +# :command.inspect_args |
| 108 | +inspect_args() { |
| 109 | + echo args: |
| 110 | + for k in "${!args[@]}"; do echo "- \${args[$k]} = ${args[$k]}"; done |
| 111 | +} |
| 112 | + |
| 113 | +# :command.command_functions |
| 114 | +# :command.function |
| 115 | +ftp_upload_command() { |
| 116 | + # :src/upload_command.sh |
| 117 | + echo "# this file is located in 'src/upload_command.sh'" |
| 118 | + echo "# code for 'ftp upload' goes here" |
| 119 | + echo "# you can edit it freely and regenerate (it will not be overwritten)" |
| 120 | + inspect_args |
| 121 | +} |
| 122 | + |
| 123 | +# :command.function |
| 124 | +ftp_download_command() { |
| 125 | + # :src/download_command.sh |
| 126 | + echo "# this file is located in 'src/download_command.sh'" |
| 127 | + echo "# code for 'ftp download' goes here" |
| 128 | + echo "# you can edit it freely and regenerate (it will not be overwritten)" |
| 129 | + inspect_args |
| 130 | +} |
| 131 | + |
| 132 | +# :command.parse_requirements |
| 133 | +parse_requirements() { |
| 134 | + # :command.fixed_flag_filter |
| 135 | + case "$1" in |
| 136 | + --version ) |
| 137 | + version_command |
| 138 | + exit 1 |
| 139 | + ;; |
| 140 | + |
| 141 | + --help | -h ) |
| 142 | + long_usage=yes |
| 143 | + ftp_usage |
| 144 | + exit 1 |
| 145 | + ;; |
| 146 | + |
| 147 | + esac |
| 148 | + # :command.environment_variables_filter |
| 149 | + # :command.dependencies_filter |
| 150 | + # :command.command_filter |
| 151 | + action=$1 |
| 152 | + |
| 153 | + case $action in |
| 154 | + -* ) |
| 155 | + ;; |
| 156 | + |
| 157 | + upload | u ) |
| 158 | + action="upload" |
| 159 | + shift |
| 160 | + ftp_upload_parse_requirements "$@" |
| 161 | + shift $# |
| 162 | + ;; |
| 163 | + |
| 164 | + download | d ) |
| 165 | + action="download" |
| 166 | + shift |
| 167 | + ftp_download_parse_requirements "$@" |
| 168 | + shift $# |
| 169 | + ;; |
| 170 | + |
| 171 | + "" ) |
| 172 | + ftp_usage |
| 173 | + exit 1 |
| 174 | + ;; |
| 175 | + |
| 176 | + * ) |
| 177 | + action="upload" |
| 178 | + ftp_upload_parse_requirements "$@" |
| 179 | + shift $# |
| 180 | + ;; |
| 181 | + |
| 182 | + esac |
| 183 | + # :command.required_args_filter |
| 184 | + # :command.required_flags_filter |
| 185 | + # :command.parse_requirements_while |
| 186 | + while [[ $# -gt 0 ]]; do |
| 187 | + key="$1" |
| 188 | + case "$key" in |
| 189 | + |
| 190 | + -* ) |
| 191 | + echo -e "invalid option: $key" |
| 192 | + exit 1 |
| 193 | + ;; |
| 194 | + |
| 195 | + * ) |
| 196 | + # :command.parse_requirements_case |
| 197 | + echo -e "invalid argument: $key" |
| 198 | + exit 1 |
| 199 | + ;; |
| 200 | + |
| 201 | + esac |
| 202 | + done |
| 203 | +} |
| 204 | + |
| 205 | +# :command.parse_requirements |
| 206 | +ftp_upload_parse_requirements() { |
| 207 | + # :command.fixed_flag_filter |
| 208 | + case "$1" in |
| 209 | + --version ) |
| 210 | + version_command |
| 211 | + exit 1 |
| 212 | + ;; |
| 213 | + |
| 214 | + --help | -h ) |
| 215 | + long_usage=yes |
| 216 | + ftp_upload_usage |
| 217 | + exit 1 |
| 218 | + ;; |
| 219 | + |
| 220 | + esac |
| 221 | + # :command.environment_variables_filter |
| 222 | + # :command.dependencies_filter |
| 223 | + # :command.command_filter |
| 224 | + action="upload" |
| 225 | + # :command.required_args_filter |
| 226 | + if [[ $1 && $1 != -* ]]; then |
| 227 | + args[source]=$1 |
| 228 | + shift |
| 229 | + else |
| 230 | + echo -e "missing required argument: SOURCE\nusage: ftp upload SOURCE [options]" |
| 231 | + exit 1 |
| 232 | + fi |
| 233 | + # :command.required_flags_filter |
| 234 | + # :command.parse_requirements_while |
| 235 | + while [[ $# -gt 0 ]]; do |
| 236 | + key="$1" |
| 237 | + case "$key" in |
| 238 | + |
| 239 | + -* ) |
| 240 | + echo -e "invalid option: $key" |
| 241 | + exit 1 |
| 242 | + ;; |
| 243 | + |
| 244 | + * ) |
| 245 | + # :command.parse_requirements_case |
| 246 | + if [[ ! ${args[source]} ]]; then |
| 247 | + args[source]=$1 |
| 248 | + shift |
| 249 | + else |
| 250 | + echo -e "invalid argument: $key" |
| 251 | + exit 1 |
| 252 | + fi |
| 253 | + ;; |
| 254 | + |
| 255 | + esac |
| 256 | + done |
| 257 | +} |
| 258 | + |
| 259 | +# :command.parse_requirements |
| 260 | +ftp_download_parse_requirements() { |
| 261 | + # :command.fixed_flag_filter |
| 262 | + case "$1" in |
| 263 | + --version ) |
| 264 | + version_command |
| 265 | + exit 1 |
| 266 | + ;; |
| 267 | + |
| 268 | + --help | -h ) |
| 269 | + long_usage=yes |
| 270 | + ftp_download_usage |
| 271 | + exit 1 |
| 272 | + ;; |
| 273 | + |
| 274 | + esac |
| 275 | + # :command.environment_variables_filter |
| 276 | + # :command.dependencies_filter |
| 277 | + # :command.command_filter |
| 278 | + action="download" |
| 279 | + # :command.required_args_filter |
| 280 | + if [[ $1 && $1 != -* ]]; then |
| 281 | + args[source]=$1 |
| 282 | + shift |
| 283 | + else |
| 284 | + echo -e "missing required argument: SOURCE\nusage: ftp download SOURCE [options]" |
| 285 | + exit 1 |
| 286 | + fi |
| 287 | + # :command.required_flags_filter |
| 288 | + # :command.parse_requirements_while |
| 289 | + while [[ $# -gt 0 ]]; do |
| 290 | + key="$1" |
| 291 | + case "$key" in |
| 292 | + |
| 293 | + -* ) |
| 294 | + echo -e "invalid option: $key" |
| 295 | + exit 1 |
| 296 | + ;; |
| 297 | + |
| 298 | + * ) |
| 299 | + # :command.parse_requirements_case |
| 300 | + if [[ ! ${args[source]} ]]; then |
| 301 | + args[source]=$1 |
| 302 | + shift |
| 303 | + else |
| 304 | + echo -e "invalid argument: $key" |
| 305 | + exit 1 |
| 306 | + fi |
| 307 | + ;; |
| 308 | + |
| 309 | + esac |
| 310 | + done |
| 311 | +} |
| 312 | + |
| 313 | +# :command.initialize |
| 314 | +initialize() { |
| 315 | + version="0.1.0" |
| 316 | + long_usage='' |
| 317 | + set -e |
| 318 | + |
| 319 | + # :src/initialize.sh |
| 320 | + # Code here runs inside the initialize() function |
| 321 | + # Use it for anything that you need to run before any other function, like |
| 322 | + # setting environment vairables: |
| 323 | + # CONFIG_FILE=settings.ini |
| 324 | + # |
| 325 | + # Feel free to empty (but not delete) this file. |
| 326 | +} |
| 327 | + |
| 328 | +# :command.run |
| 329 | +run() { |
| 330 | + declare -A args |
| 331 | + parse_requirements "$@" |
| 332 | + |
| 333 | + if [[ $action == "upload" ]]; then |
| 334 | + if [[ ${args[--help]} ]]; then |
| 335 | + long_usage=yes |
| 336 | + ftp_upload_usage |
| 337 | + else |
| 338 | + ftp_upload_command |
| 339 | + fi |
| 340 | + |
| 341 | + elif [[ $action == "download" ]]; then |
| 342 | + if [[ ${args[--help]} ]]; then |
| 343 | + long_usage=yes |
| 344 | + ftp_download_usage |
| 345 | + else |
| 346 | + ftp_download_command |
| 347 | + fi |
| 348 | + |
| 349 | + elif [[ ${args[--version]} ]]; then |
| 350 | + version_command |
| 351 | + elif [[ ${args[--help]} ]]; then |
| 352 | + long_usage=yes |
| 353 | + ftp_usage |
| 354 | + elif [[ $action == "root" ]]; then |
| 355 | + root_command |
| 356 | + fi |
| 357 | +} |
| 358 | + |
| 359 | +initialize |
| 360 | +run "$@" |
0 commit comments