Example Function Commands

Updated 1 month ago by Copado Solutions

In this article, we will go over some useful commands you can include in your script when running a Copado function. If you want to take a look at some example scripts, please review the article Example Function Scripts.

copado 

You can call the copado command to set the progress of the job, optionally adding an error message or the result information:

usage: copado [-h] [-p PROGRESS_MESSAGE] [-e ERROR_MESSAGE] [-r RESULT_DATA]
-p PROGRESS_MESSAGE, --progress PROGRESS_MESSAGE
-e ERROR_MESSAGE, --error-message ERROR_MESSAGE
-r RESULT_DATA, --result-data RESULT_DATA
Examples:
copado --progress "concise progress message..."
copado -p "unexpected error" --error-message "there was an error attempting the connection... error=${error_messsage}"
copado -p "process finished" --result-data "{"result": "success", ...}"

Please note that while the copado -e and copado -r commands are optional, the copado -p command is required.

You can also call the copado command to attach local files as Salesforce files associated with the Result record, and you can give them an optional name in Salesforce different from the local file: 

usage: copado [-h] [-u UPLOAD_FILE] [-n NAME] [-i PARENTID]

Examples:
copado --uploadfile /tmp/result.txt
copado -u /tmp/tmp.png --name "Chart of sales.png"
copado -u /tmp/tmp.png --parentid “a1r6I000002uNuIPAT”

copado-git-get

The copado-git-get command is a utility function to simplify Git initialization and other read operations. It can be called multiple times in the same directory, or in separate directories, in order to initialize, fetch and checkout any branch:

usage: copado-git-get [-h] [-d DIRECTORY] [--depth DEPTH] [-v] [-c] BRANCH
-d DIRECTORY, --directory DIRECTORY
Root directory of the repository. Defaults to the current directory
--depth DEPTH     git DEPTH for shallow cloning. Default is no shallow cloning
-c, --create      if BRANCH does not exist, create it locally instead of throwing an error
-v, --verbose         enable git verbose / progress output

Example 1:
copado-git-get main
# fetch or create the branch "testing-branch" from the previous branch "main"
copado-git-get -c "testing-branch"

Example 2:
# create the needed directories
mkdir /tmp/repository_main /tmp/repository_testing

# clone the repository twice, fetching only the last commit of each branch
copado-git-get --depth 1 -d /tmp/repository_main main
copado-git-get --depth 1 -d /tmp/repository_testing testing

# show the different file names between the two branches.
diff -q /tmp/repository_main /tmp/repository_testing 


How did we do?