├── .bash_helpers.sh ├── .editorconfig ├── .gitignore ├── CODE_OF_CONDUCT.md ├── LICENSE ├── README.md ├── SECURITY.md ├── SUPPORT.md ├── examples ├── .extensions │ └── az.sh └── creating_new_command.sh └── install.sh /.bash_helpers.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # declare global key-value pair variable 4 | declare -g -A __COMMAND_EXTENSIONS 5 | 6 | # to extend a command, start with a function that has the same name as the command 7 | function add_extension() { 8 | POSITIONAL_ARGS=() 9 | 10 | while [[ $# -gt 0 ]]; do 11 | case ${1} in 12 | -c|--command-name) 13 | COMMAND_NAME="$2" 14 | shift 15 | shift 16 | ;; 17 | -s|--sub-command-name) 18 | SUB_COMMAND_NAME="$2" 19 | shift 20 | shift 21 | ;; 22 | -a|--argument-name) 23 | ARGUMENT_NAME="$2" 24 | shift 25 | shift 26 | ;; 27 | -r|--run) 28 | RUN="$2" 29 | shift 30 | shift 31 | ;; 32 | -*|--*) 33 | echo "Unknown option ${1}" 34 | exit 1 35 | ;; 36 | *) 37 | POSITIONAL_ARGS+=("${1}") 38 | shift 39 | ;; 40 | esac 41 | done 42 | 43 | set -- "${POSITIONAL_ARGS[@]}" 44 | 45 | local key=${COMMAND_NAME} 46 | local value=${__COMMAND_EXTENSIONS[${key}]} 47 | 48 | value="${value}$(cat < /dev/null || return 1 63 | eval "$(echo "${2}()"; declare -f ${1} | tail -n +2)" 64 | } 65 | 66 | function setup_extensions() { 67 | if [[ -d ~/.extensions ]]; then 68 | for entry in ~/.extensions/*.sh; do 69 | source ${entry} 70 | 71 | FILE_NAME=${entry##*/} 72 | COMMAND_NAME="${FILE_NAME%.*}" 73 | 74 | COMMAND_INFO_JSON=$(_get_extension_info_json) 75 | 76 | for (( i=0; i<$(echo "${COMMAND_INFO_JSON}" | jq ". | length"); i++ )); do 77 | SUB_COMMAND_NAME=$(echo "${COMMAND_INFO_JSON}" | jq -r ".[${i}].SUB_COMMAND_NAME") 78 | ARGUMENT_NAME=$(echo "${COMMAND_INFO_JSON}" | jq -r ".[${i}].ARGUMENT_NAME") 79 | METHOD_NAME=$(echo "${COMMAND_INFO_JSON}" | jq -r ".[${i}].METHOD_NAME") 80 | 81 | FUNCTION_NAME="$(echo ${COMMAND_NAME}_${SUB_COMMAND_NAME}_${ARGUMENT_NAME} | sed -e 's/[^a-zA-Z0-9_]//g' -e 's/ /_/g')" 82 | 83 | copy_function "${METHOD_NAME}" ${FUNCTION_NAME} 84 | 85 | add_extension \ 86 | --command-name "${COMMAND_NAME}" \ 87 | --sub-command-name "${SUB_COMMAND_NAME}" \ 88 | --argument-name "${ARGUMENT_NAME}" \ 89 | --run "${FUNCTION_NAME}" 90 | done 91 | done 92 | fi 93 | 94 | if [[ -d ~/.amplify/extensions ]]; then 95 | for entry in ~/.amplify/extensions/*.sh; do 96 | source ${entry} 97 | 98 | FILE_NAME=${entry##*/} 99 | COMMAND_NAME="${FILE_NAME%.*}" 100 | 101 | COMMAND_INFO_JSON=$(_get_extension_info_json) 102 | 103 | for (( i=0; i<$(echo "${COMMAND_INFO_JSON}" | jq ". | length"); i++ )); do 104 | SUB_COMMAND_NAME=$(echo "${COMMAND_INFO_JSON}" | jq -r ".[${i}].SUB_COMMAND_NAME") 105 | ARGUMENT_NAME=$(echo "${COMMAND_INFO_JSON}" | jq -r ".[${i}].ARGUMENT_NAME") 106 | METHOD_NAME=$(echo "${COMMAND_INFO_JSON}" | jq -r ".[${i}].METHOD_NAME") 107 | 108 | FUNCTION_NAME="$(echo ${COMMAND_NAME}_${SUB_COMMAND_NAME}_${ARGUMENT_NAME} | sed -e 's/[^a-zA-Z0-9_]//g' -e 's/ /_/g')" 109 | 110 | copy_function "${METHOD_NAME}" ${FUNCTION_NAME} 111 | 112 | add_extension \ 113 | --command-name "${COMMAND_NAME}" \ 114 | --sub-command-name "${SUB_COMMAND_NAME}" \ 115 | --argument-name "${ARGUMENT_NAME}" \ 116 | --run "${FUNCTION_NAME}" 117 | done 118 | done 119 | fi 120 | 121 | for COMMAND_NAME in "${!__COMMAND_EXTENSIONS[@]}"; do 122 | eval "$(cat < 2 | 3 | ## Security 4 | 5 | Microsoft takes the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations, which include [Microsoft](https://github.com/Microsoft), [Azure](https://github.com/Azure), [DotNet](https://github.com/dotnet), [AspNet](https://github.com/aspnet), [Xamarin](https://github.com/xamarin), and [our GitHub organizations](https://opensource.microsoft.com/). 6 | 7 | If you believe you have found a security vulnerability in any Microsoft-owned repository that meets [Microsoft's definition of a security vulnerability](https://docs.microsoft.com/en-us/previous-versions/tn-archive/cc751383(v=technet.10)), please report it to us as described below. 8 | 9 | ## Reporting Security Issues 10 | 11 | **Please do not report security vulnerabilities through public GitHub issues.** 12 | 13 | Instead, please report them to the Microsoft Security Response Center (MSRC) at [https://msrc.microsoft.com/create-report](https://msrc.microsoft.com/create-report). 14 | 15 | If you prefer to submit without logging in, send email to [secure@microsoft.com](mailto:secure@microsoft.com). If possible, encrypt your message with our PGP key; please download it from the [Microsoft Security Response Center PGP Key page](https://www.microsoft.com/en-us/msrc/pgp-key-msrc). 16 | 17 | You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Additional information can be found at [microsoft.com/msrc](https://www.microsoft.com/msrc). 18 | 19 | Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue: 20 | 21 | * Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.) 22 | * Full paths of source file(s) related to the manifestation of the issue 23 | * The location of the affected source code (tag/branch/commit or direct URL) 24 | * Any special configuration required to reproduce the issue 25 | * Step-by-step instructions to reproduce the issue 26 | * Proof-of-concept or exploit code (if possible) 27 | * Impact of the issue, including how an attacker might exploit the issue 28 | 29 | This information will help us triage your report more quickly. 30 | 31 | If you are reporting for a bug bounty, more complete reports can contribute to a higher bounty award. Please visit our [Microsoft Bug Bounty Program](https://microsoft.com/msrc/bounty) page for more details about our active programs. 32 | 33 | ## Preferred Languages 34 | 35 | We prefer all communications to be in English. 36 | 37 | ## Policy 38 | 39 | Microsoft follows the principle of [Coordinated Vulnerability Disclosure](https://www.microsoft.com/en-us/msrc/cvd). 40 | 41 | -------------------------------------------------------------------------------- /SUPPORT.md: -------------------------------------------------------------------------------- 1 | # Support 2 | 3 | ## How to file issues and get help 4 | 5 | This project uses GitHub Issues to track bugs and feature requests. Please search the existing 6 | issues before filing new issues to avoid duplicates. For new issues, file your bug or 7 | feature request as a new Issue. 8 | 9 | For help and questions about using this project, please **REPO MAINTAINER: INSERT INSTRUCTIONS HERE 10 | FOR HOW TO ENGAGE REPO OWNERS OR COMMUNITY FOR HELP. COULD BE A STACK OVERFLOW TAG OR OTHER 11 | CHANNEL. WHERE WILL YOU HELP PEOPLE?**. 12 | 13 | ## Microsoft Support Policy 14 | 15 | Support for this **PROJECT or PRODUCT** is limited to the resources listed above. 16 | -------------------------------------------------------------------------------- /examples/.extensions/az.sh: -------------------------------------------------------------------------------- 1 | function _get_extension_info_json() { 2 | echo $(cat < /dev/null 2>&1; then 10 | gh repo clone microsoft/amplify ~/.amplify 11 | else 12 | git clone https://github.com/microsoft/amplify.git ~/.amplify 13 | fi 14 | 15 | # make amplify persistent 16 | echo -e "\nsource ~/.amplify/.bash_helpers.sh\n\nsetup_extensions\n" >> ~/.bashrc 17 | 18 | # done 19 | echo $'\n########\ndone\n' 20 | --------------------------------------------------------------------------------