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