Skip to content

Commit

Permalink
[FEATURE] Add -SM/-sm/--share-mode flag | Resolve #139
Browse files Browse the repository at this point in the history
Specify the share mode for sharing file.

    Share modes are:

    - r / reader - Read only permission.

    - w / writer - Read and write permission.

    - c / commenter - Comment only permission.

    Note: Although this flag is independent of --share flag but when email is needed, then --share flag use is neccessary.

In output, show which mode used for sharing file

	(SHARED[w]) means shared with write perms
  • Loading branch information
Akianonymus committed May 10, 2021
1 parent 346e118 commit 704cdec
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 20 deletions.
14 changes: 14 additions & 0 deletions README.md
Expand Up @@ -552,6 +552,20 @@ These are the custom flags that are currently implemented:

---

- <strong>-SM | -sm | --share-mode 'share mode'</strong>

Specify the share mode for sharing file.

Share modes are:

- r / reader - Read only permission.
- w / writer - Read and write permission.
- c / commenter - Comment only permission.

Note: Although this flag is independent of --share flag but when email is needed, then --share flag use is neccessary.

---

- <strong>--speed 'speed'</strong>

Limit the download speed, supported formats: 1K, 1M and 1G.
Expand Down
2 changes: 1 addition & 1 deletion bash/drive-utils.bash
Expand Up @@ -394,7 +394,7 @@ _full_upload() {
###################################################
_share_id() {
[[ $# -lt 2 ]] && printf "%s: Missing arguments\n" "${FUNCNAME[0]}" && return 1
declare id="${1}" share_email="${2}" role="reader"
declare id="${1}" role="${2:?Missing role}" share_email="${3}"
declare type="${share_email:+user}" share_post_data share_post_data share_response

"${EXTRA_LOG}" "justify" "Sharing.." "-" 1>&2
Expand Down
30 changes: 25 additions & 5 deletions bash/release/gupload
Expand Up @@ -1318,7 +1318,7 @@ _full_upload() {
###################################################
_share_id() {
[[ $# -lt 2 ]] && printf "%s: Missing arguments\n" "${FUNCNAME[0]}" && return 1
declare id="${1}" share_email="${2}" role="reader"
declare id="${1}" role="${2:?Missing role}" share_email="${3}"
declare type="${share_email:+user}" share_post_data share_post_data share_response

"${EXTRA_LOG}" "justify" "Sharing.." "-" 1>&2
Expand Down Expand Up @@ -1554,6 +1554,11 @@ Options:\n
Note: For files inside folders, use --description-all flag.\n
-d | --skip-duplicates - Do not upload the files with the same name, if already present in the root folder/input folder, also works with recursive folders.\n
-S | --share <optional_email_address>- Share the uploaded input file/folder, grant reader permission to provided email address or to everyone with the shareable link.\n
-SM | -sm | --share-mode 'share mode' - Specify the share mode for sharing file.\n
Share modes are: r / reader - Read only permission.\n
: w / writer - Read and write permission.\n
: c / commenter - Comment only permission.\n
Note: Although this flag is independent of --share flag but when email is needed, then --share flag use is neccessary.\n
--speed 'speed' - Limit the download speed, supported formats: 1K, 1M and 1G.\n
-i | --save-info <file_to_save_info> - Save uploaded files info to the given filename.\n
-z | --config <config_path> - Override default config file with custom config file.\nIf you want to change default value, then use this format -z/--config default=default=your_config_file_path.\n
Expand Down Expand Up @@ -1646,7 +1651,7 @@ _setup_arguments() {
# De-initialize if any variables set already.
unset LIST_ACCOUNTS UPDATE_DEFAULT_ACCOUNT CUSTOM_ACCOUNT_NAME NEW_ACCOUNT_NAME DELETE_ACCOUNT_NAME ACCOUNT_ONLY_RUN
unset FOLDERNAME LOCAL_INPUT_ARRAY ID_INPUT_ARRAY CONTINUE_WITH_NO_INPUT
unset PARALLEL NO_OF_PARALLEL_JOBS SHARE SHARE_EMAIL OVERWRITE SKIP_DUPLICATES DESCRIPTION SKIP_SUBDIRS ROOTDIR QUIET
unset PARALLEL NO_OF_PARALLEL_JOBS SHARE SHARE_ROLE SHARE_EMAIL OVERWRITE SKIP_DUPLICATES DESCRIPTION SKIP_SUBDIRS ROOTDIR QUIET
unset VERBOSE VERBOSE_PROGRESS DEBUG LOG_FILE_ID CURL_SPEED RETRY
export CURL_PROGRESS="-s" EXTRA_LOG=":" CURL_PROGRESS_EXTRA="-s"
INFO_PATH="${HOME}/.google-drive-upload" CONFIG_INFO="${INFO_PATH}/google-drive-upload.configpath"
Expand Down Expand Up @@ -1748,6 +1753,21 @@ _setup_arguments() {
if [[ -n ${2} && ! ${2} = -* && ${2} =~ ${EMAIL_REGEX} ]]; then
SHARE_EMAIL="${2}" && shift && export SHARE_EMAIL
fi
SHARE_ROLE="${SHARE_ROLE:-reader}"
;;
-[Ss][Mm] | --share-mode)
_check_longoptions "${1}" "${2}"
case "${2}" in
r | read*) SHARE_ROLE="reader" ;;
w | write*) SHARE_ROLE="writer" ;;
c | comment*) SHARE_ROLE="commenter" ;;
*)
printf "%s\n" "Invalid share mode given ( ${2} ). Supported values are r or reader / w or writer / c or commenter." &&
exit 1
;;
esac
SHARE="_share_id"
shift
;;
--speed)
_check_longoptions "${1}" "${2}"
Expand Down Expand Up @@ -1928,7 +1948,7 @@ _setup_workspace() {
# WORKSPACE_FOLDER_ID, UPLOAD_MODE, SKIP_DUPLICATES, OVERWRITE, SHARE,
# UPLOAD_STATUS, COLUMNS, API_URL, API_VERSION, TOKEN_URL, LOG_FILE_ID
# FILE_ID, FILE_LINK, FINAL_ID_INPUT_ARRAY ( array )
# PARALLEL_UPLOAD, QUIET, NO_OF_PARALLEL_JOBS, TMPFILE
# PARALLEL_UPLOAD, QUIET, NO_OF_PARALLEL_JOBS, TMPFILE, SHARE_ROLE
# Functions - _print_center, _clear_line, _newline, _support_ansi_escapes, _print_center_quiet
# _upload_file, _share_id, _is_terminal, _dirname,
# _create_directory, _json_value, _url_encode, _check_existing_file, _bytes_to_human
Expand All @@ -1939,9 +1959,9 @@ _setup_workspace() {
_process_arguments() {
# on successful uploads
_share_and_print_link() {
"${SHARE:-:}" "${1:-}" "${SHARE_EMAIL}"
"${SHARE:-:}" "${1:-}" "${SHARE_ROLE}" "${SHARE_EMAIL}"
[[ -z ${HIDE_INFO} ]] && {
_print_center "justify" "DriveLink" "${SHARE:+ (SHARED)}" "-"
_print_center "justify" "DriveLink" "${SHARE:+ (SHARED[${SHARE_ROLE:0:1}])}" "-"
_support_ansi_escapes && [[ ${COLUMNS} -gt 45 ]] && _print_center "normal" "↓ ↓ ↓" ' '
"${QUIET:-_print_center}" "normal" "https://drive.google.com/open?id=${1:-}" " "
}
Expand Down
28 changes: 24 additions & 4 deletions bash/upload.bash
Expand Up @@ -28,6 +28,11 @@ Options:\n
Note: For files inside folders, use --description-all flag.\n
-d | --skip-duplicates - Do not upload the files with the same name, if already present in the root folder/input folder, also works with recursive folders.\n
-S | --share <optional_email_address>- Share the uploaded input file/folder, grant reader permission to provided email address or to everyone with the shareable link.\n
-SM | -sm | --share-mode 'share mode' - Specify the share mode for sharing file.\n
Share modes are: r / reader - Read only permission.\n
: w / writer - Read and write permission.\n
: c / commenter - Comment only permission.\n
Note: Although this flag is independent of --share flag but when email is needed, then --share flag use is neccessary.\n
--speed 'speed' - Limit the download speed, supported formats: 1K, 1M and 1G.\n
-i | --save-info <file_to_save_info> - Save uploaded files info to the given filename.\n
-z | --config <config_path> - Override default config file with custom config file.\nIf you want to change default value, then use this format -z/--config default=default=your_config_file_path.\n
Expand Down Expand Up @@ -120,7 +125,7 @@ _setup_arguments() {
# De-initialize if any variables set already.
unset LIST_ACCOUNTS UPDATE_DEFAULT_ACCOUNT CUSTOM_ACCOUNT_NAME NEW_ACCOUNT_NAME DELETE_ACCOUNT_NAME ACCOUNT_ONLY_RUN
unset FOLDERNAME LOCAL_INPUT_ARRAY ID_INPUT_ARRAY CONTINUE_WITH_NO_INPUT
unset PARALLEL NO_OF_PARALLEL_JOBS SHARE SHARE_EMAIL OVERWRITE SKIP_DUPLICATES DESCRIPTION SKIP_SUBDIRS ROOTDIR QUIET
unset PARALLEL NO_OF_PARALLEL_JOBS SHARE SHARE_ROLE SHARE_EMAIL OVERWRITE SKIP_DUPLICATES DESCRIPTION SKIP_SUBDIRS ROOTDIR QUIET
unset VERBOSE VERBOSE_PROGRESS DEBUG LOG_FILE_ID CURL_SPEED RETRY
export CURL_PROGRESS="-s" EXTRA_LOG=":" CURL_PROGRESS_EXTRA="-s"
INFO_PATH="${HOME}/.google-drive-upload" CONFIG_INFO="${INFO_PATH}/google-drive-upload.configpath"
Expand Down Expand Up @@ -222,6 +227,21 @@ _setup_arguments() {
if [[ -n ${2} && ! ${2} = -* && ${2} =~ ${EMAIL_REGEX} ]]; then
SHARE_EMAIL="${2}" && shift && export SHARE_EMAIL
fi
SHARE_ROLE="${SHARE_ROLE:-reader}"
;;
-[Ss][Mm] | --share-mode)
_check_longoptions "${1}" "${2}"
case "${2}" in
r | read*) SHARE_ROLE="reader" ;;
w | write*) SHARE_ROLE="writer" ;;
c | comment*) SHARE_ROLE="commenter" ;;
*)
printf "%s\n" "Invalid share mode given ( ${2} ). Supported values are r or reader / w or writer / c or commenter." &&
exit 1
;;
esac
SHARE="_share_id"
shift
;;
--speed)
_check_longoptions "${1}" "${2}"
Expand Down Expand Up @@ -402,7 +422,7 @@ _setup_workspace() {
# WORKSPACE_FOLDER_ID, UPLOAD_MODE, SKIP_DUPLICATES, OVERWRITE, SHARE,
# UPLOAD_STATUS, COLUMNS, API_URL, API_VERSION, TOKEN_URL, LOG_FILE_ID
# FILE_ID, FILE_LINK, FINAL_ID_INPUT_ARRAY ( array )
# PARALLEL_UPLOAD, QUIET, NO_OF_PARALLEL_JOBS, TMPFILE
# PARALLEL_UPLOAD, QUIET, NO_OF_PARALLEL_JOBS, TMPFILE, SHARE_ROLE
# Functions - _print_center, _clear_line, _newline, _support_ansi_escapes, _print_center_quiet
# _upload_file, _share_id, _is_terminal, _dirname,
# _create_directory, _json_value, _url_encode, _check_existing_file, _bytes_to_human
Expand All @@ -413,9 +433,9 @@ _setup_workspace() {
_process_arguments() {
# on successful uploads
_share_and_print_link() {
"${SHARE:-:}" "${1:-}" "${SHARE_EMAIL}"
"${SHARE:-:}" "${1:-}" "${SHARE_ROLE}" "${SHARE_EMAIL}"
[[ -z ${HIDE_INFO} ]] && {
_print_center "justify" "DriveLink" "${SHARE:+ (SHARED)}" "-"
_print_center "justify" "DriveLink" "${SHARE:+ (SHARED[${SHARE_ROLE:0:1}])}" "-"
_support_ansi_escapes && [[ ${COLUMNS} -gt 45 ]] && _print_center "normal" "↓ ↓ ↓" ' '
"${QUIET:-_print_center}" "normal" "https://drive.google.com/open?id=${1:-}" " "
}
Expand Down
2 changes: 1 addition & 1 deletion sh/drive-utils.sh
Expand Up @@ -398,7 +398,7 @@ _full_upload() {
###################################################
_share_id() {
[ $# -lt 2 ] && printf "Missing arguments\n" && return 1
id_share_id="${1}" share_email_share_id="${2}" role_share_id="reader" type_share_id="${share_email_share_id:+user}"
id_share_id="${1}" role_share_id="${2:?Missing role}" share_email_share_id="${3}" role_share_id="reader" type_share_id="${share_email_share_id:+user}"
unset post_data_share_id response_share_id
"${EXTRA_LOG}" "justify" "Sharing.." "-" 1>&2
Expand Down
30 changes: 25 additions & 5 deletions sh/release/gupload
Expand Up @@ -1263,7 +1263,7 @@ _full_upload() {
###################################################
_share_id() {
[ $# -lt 2 ] && printf "Missing arguments\n" && return 1
id_share_id="${1}" share_email_share_id="${2}" role_share_id="reader" type_share_id="${share_email_share_id:+user}"
id_share_id="${1}" role_share_id="${2:?Missing role}" share_email_share_id="${3}" role_share_id="reader" type_share_id="${share_email_share_id:+user}"
unset post_data_share_id response_share_id
"${EXTRA_LOG}" "justify" "Sharing.." "-" 1>&2
Expand Down Expand Up @@ -1480,6 +1480,11 @@ Options:\n
Note: For files inside folders, use --description-all flag.\n
-d | --skip-duplicates - Do not upload the files with the same name, if already present in the root folder/input folder, also works with recursive folders.\n
-S | --share <optional_email_address>- Share the uploaded input file/folder, grant reader permission to provided email address or to everyone with the shareable link.\n
-SM | -sm | --share-mode 'share mode' - Specify the share mode for sharing file.\n
Share modes are: r / reader - Read only permission.\n
: w / writer - Read and write permission.\n
: c / commenter - Comment only permission.\n
Note: Although this flag is independent of --share flag but when email is needed, then --share flag use is neccessary.\n
--speed 'speed' - Limit the download speed, supported formats: 1K, 1M and 1G.\n
-i | --save-info <file_to_save_info> - Save uploaded files info to the given filename.\n
-z | --config <config_path> - Override default config file with custom config file.\nIf you want to change default value, then use this format -z/--config default=default=your_config_file_path.\n
Expand Down Expand Up @@ -1574,7 +1579,7 @@ _setup_arguments() {
# De-initialize if any variables set already.
unset LIST_ACCOUNTS UPDATE_DEFAULT_ACCOUNT CUSTOM_ACCOUNT_NAME NEW_ACCOUNT_NAME DELETE_ACCOUNT_NAME ACCOUNT_ONLY_RUN
unset FOLDERNAME FINAL_LOCAL_INPUT_ARRAY FINAL_ID_INPUT_ARRAY CONTINUE_WITH_NO_INPUT
unset PARALLEL NO_OF_PARALLEL_JOBS SHARE SHARE_EMAIL OVERWRITE SKIP_DUPLICATES SKIP_SUBDIRS DESCRIPTION ROOTDIR QUIET
unset PARALLEL NO_OF_PARALLEL_JOBS SHARE SHARE_EMAIL SHARE_ROLE OVERWRITE SKIP_DUPLICATES SKIP_SUBDIRS DESCRIPTION ROOTDIR QUIET
unset VERBOSE VERBOSE_PROGRESS DEBUG LOG_FILE_ID CURL_SPEED RETRY
export CURL_PROGRESS="-s" EXTRA_LOG=":" CURL_PROGRESS_EXTRA="-s"
INFO_PATH="${HOME}/.google-drive-upload" CONFIG_INFO="${INFO_PATH}/google-drive-upload.configpath"
Expand Down Expand Up @@ -1683,6 +1688,21 @@ _setup_arguments() {
fi
;;
esac
SHARE_ROLE="${SHARE_ROLE:-reader}"
;;
-[Ss][Mm] | --share-mode)
_check_longoptions "${1}" "${2}"
case "${2}" in
r | read*) SHARE_ROLE="reader" ;;
w | write*) SHARE_ROLE="writer" ;;
c | comment*) SHARE_ROLE="commenter" ;;
*)
printf "%s\n" "Invalid share mode given ( ${2} ). Supported values are r or reader / w or writer / c or commenter." &&
exit 1
;;
esac
SHARE="_share_id"
shift
;;
--speed)
_check_longoptions "${1}" "${2}"
Expand Down Expand Up @@ -1869,7 +1889,7 @@ _setup_workspace() {
# WORKSPACE_FOLDER_ID, UPLOAD_MODE, SKIP_DUPLICATES, OVERWRITE, SHARE,
# UPLOAD_STATUS, COLUMNS, API_URL, API_VERSION, TOKEN_URL, LOG_FILE_ID
# FILE_ID, FILE_LINK, FINAL_ID_INPUT_ARRAY ( array )
# PARALLEL_UPLOAD, QUIET, NO_OF_PARALLEL_JOBS, TMPFILE
# PARALLEL_UPLOAD, QUIET, NO_OF_PARALLEL_JOBS, TMPFILE, SHARE_ROLE
# Functions - _print_center, _clear_line, _newline, _support_ansi_escapes, _print_center_quiet
# _upload_file, _share_id, _is_terminal, _dirname,
# _create_directory, _json_value, _url_encode, _check_existing_file, _bytes_to_human
Expand All @@ -1881,9 +1901,9 @@ _process_arguments() {
export SOURCE_UTILS
# on successful uploads
_share_and_print_link() {
"${SHARE:-:}" "${1:-}" "${SHARE_EMAIL}"
"${SHARE:-:}" "${1:-}" "${SHARE_ROLE}" "${SHARE_EMAIL}"
[ -z "${HIDE_INFO}" ] && {
_print_center "justify" "DriveLink" "${SHARE:+ (SHARED)}" "-"
_print_center "justify" "DriveLink" "${SHARE:+ (SHARED[$(printf "%.1s" "${SHARE_ROLE}")])}" "-"
_support_ansi_escapes && [ "$((COLUMNS))" -gt 45 ] 2>| /dev/null && _print_center "normal" '^ ^ ^' ' '
"${QUIET:-_print_center}" "normal" "https://drive.google.com/open?id=${1:-}" " "
}
Expand Down
28 changes: 24 additions & 4 deletions sh/upload.sh
Expand Up @@ -28,6 +28,11 @@ Options:\n
Note: For files inside folders, use --description-all flag.\n
-d | --skip-duplicates - Do not upload the files with the same name, if already present in the root folder/input folder, also works with recursive folders.\n
-S | --share <optional_email_address>- Share the uploaded input file/folder, grant reader permission to provided email address or to everyone with the shareable link.\n
-SM | -sm | --share-mode 'share mode' - Specify the share mode for sharing file.\n
Share modes are: r / reader - Read only permission.\n
: w / writer - Read and write permission.\n
: c / commenter - Comment only permission.\n
Note: Although this flag is independent of --share flag but when email is needed, then --share flag use is neccessary.\n
--speed 'speed' - Limit the download speed, supported formats: 1K, 1M and 1G.\n
-i | --save-info <file_to_save_info> - Save uploaded files info to the given filename.\n
-z | --config <config_path> - Override default config file with custom config file.\nIf you want to change default value, then use this format -z/--config default=default=your_config_file_path.\n
Expand Down Expand Up @@ -122,7 +127,7 @@ _setup_arguments() {
# De-initialize if any variables set already.
unset LIST_ACCOUNTS UPDATE_DEFAULT_ACCOUNT CUSTOM_ACCOUNT_NAME NEW_ACCOUNT_NAME DELETE_ACCOUNT_NAME ACCOUNT_ONLY_RUN
unset FOLDERNAME FINAL_LOCAL_INPUT_ARRAY FINAL_ID_INPUT_ARRAY CONTINUE_WITH_NO_INPUT
unset PARALLEL NO_OF_PARALLEL_JOBS SHARE SHARE_EMAIL OVERWRITE SKIP_DUPLICATES SKIP_SUBDIRS DESCRIPTION ROOTDIR QUIET
unset PARALLEL NO_OF_PARALLEL_JOBS SHARE SHARE_EMAIL SHARE_ROLE OVERWRITE SKIP_DUPLICATES SKIP_SUBDIRS DESCRIPTION ROOTDIR QUIET
unset VERBOSE VERBOSE_PROGRESS DEBUG LOG_FILE_ID CURL_SPEED RETRY
export CURL_PROGRESS="-s" EXTRA_LOG=":" CURL_PROGRESS_EXTRA="-s"
INFO_PATH="${HOME}/.google-drive-upload" CONFIG_INFO="${INFO_PATH}/google-drive-upload.configpath"
Expand Down Expand Up @@ -231,6 +236,21 @@ _setup_arguments() {
fi
;;
esac
SHARE_ROLE="${SHARE_ROLE:-reader}"
;;
-[Ss][Mm] | --share-mode)
_check_longoptions "${1}" "${2}"
case "${2}" in
r | read*) SHARE_ROLE="reader" ;;
w | write*) SHARE_ROLE="writer" ;;
c | comment*) SHARE_ROLE="commenter" ;;
*)
printf "%s\n" "Invalid share mode given ( ${2} ). Supported values are r or reader / w or writer / c or commenter." &&
exit 1
;;
esac
SHARE="_share_id"
shift
;;
--speed)
_check_longoptions "${1}" "${2}"
Expand Down Expand Up @@ -417,7 +437,7 @@ _setup_workspace() {
# WORKSPACE_FOLDER_ID, UPLOAD_MODE, SKIP_DUPLICATES, OVERWRITE, SHARE,
# UPLOAD_STATUS, COLUMNS, API_URL, API_VERSION, TOKEN_URL, LOG_FILE_ID
# FILE_ID, FILE_LINK, FINAL_ID_INPUT_ARRAY ( array )
# PARALLEL_UPLOAD, QUIET, NO_OF_PARALLEL_JOBS, TMPFILE
# PARALLEL_UPLOAD, QUIET, NO_OF_PARALLEL_JOBS, TMPFILE, SHARE_ROLE
# Functions - _print_center, _clear_line, _newline, _support_ansi_escapes, _print_center_quiet
# _upload_file, _share_id, _is_terminal, _dirname,
# _create_directory, _json_value, _url_encode, _check_existing_file, _bytes_to_human
Expand All @@ -429,9 +449,9 @@ _process_arguments() {
export SOURCE_UTILS
# on successful uploads
_share_and_print_link() {
"${SHARE:-:}" "${1:-}" "${SHARE_EMAIL}"
"${SHARE:-:}" "${1:-}" "${SHARE_ROLE}" "${SHARE_EMAIL}"
[ -z "${HIDE_INFO}" ] && {
_print_center "justify" "DriveLink" "${SHARE:+ (SHARED)}" "-"
_print_center "justify" "DriveLink" "${SHARE:+ (SHARED[$(printf "%.1s" "${SHARE_ROLE}")])}" "-"
_support_ansi_escapes && [ "$((COLUMNS))" -gt 45 ] 2>| /dev/null && _print_center "normal" '^ ^ ^' ' '
"${QUIET:-_print_center}" "normal" "https://drive.google.com/open?id=${1:-}" " "
}
Expand Down

0 comments on commit 704cdec

Please sign in to comment.