Skip to content

Commit

Permalink
Removing Interactive Mode for Windows users (#229)
Browse files Browse the repository at this point in the history
* Removed interactive mode for windows
* Adding a small note on readme to mention interactive mode is only for non-win users
* Fixing Update script for checking windows OS name correctly
* Renaming var ARCHITECTURE to OS
  • Loading branch information
harinee committed Aug 21, 2020
1 parent 1fecebc commit 7e0ea2e
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 45 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,9 @@ fileignoreconfig:
Entering this in the `.talismanrc` file will ensure that Talisman will ignore the `danger.pem` file as long as the checksum matches the value mentioned in the `checksum` field.

### Interactive mode

**Available only for non-Windows users**

If it is too much of a hassle to keep copying content to .talismanrc everytime you encounter an error from Talisman, you could enable the interactive mode and let Talisman assist you in prompting the additions of the files to ignore.
Just follow the simple steps:
1. Open your bash profile where your environment variables are set (.bashrc, .bash_profile, .profile or any other location)
Expand Down
3 changes: 2 additions & 1 deletion detector/helpers/detection_results.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"log"
"os"
"runtime"
"strings"
"talisman/detector/severity"
"talisman/gitrepo"
Expand Down Expand Up @@ -315,7 +316,7 @@ func (r *DetectionResults) suggestTalismanRC(filePaths []string, promptContext p
entriesToAdd = append(entriesToAdd, fileIgnoreConfig)
}

if promptContext.Interactive {
if promptContext.Interactive && runtime.GOOS != "windows" {
confirmedEntries := getUserConfirmation(entriesToAdd, promptContext)
talismanrc.Get().AddFileIgnores(confirmedEntries)
} else {
Expand Down
43 changes: 25 additions & 18 deletions global_install_scripts/install.bash
Original file line number Diff line number Diff line change
Expand Up @@ -78,37 +78,40 @@ function run() {
cat ${TEMP_DIR}/download_urls
}

function set_talisman_binary_name() {
# based on OS (linux/darwin) and ARCH(32/64 bit)
declare ARCHITECTURE
OS=$(uname -s)
case $OS in
function operating_system() {
OS=$(uname -s)
case $OS in
"Linux")
ARCHITECTURE="linux"
echo "linux"
;;
"Darwin")
ARCHITECTURE="darwin"
echo "darwin"
;;
MINGW32_NT-10.0-WOW*)
ARCHITECTURE="windows"
echo "windows"
;;
MINGW64_NT-10.0*)
ARCHITECTURE="windows"
echo "windows"
;;
*)
echo_error "Talisman currently only supports Windows, Linux and MacOS(darwin) systems."
echo_error "If this is a problem for you, please open an issue: https://github.com/${INSTALL_ORG_REPO}/issues/new"
exit $E_UNSUPPORTED_ARCH
;;
esac
}

function set_talisman_binary_name() {
# based on OS (linux/darwin) and ARCH(32/64 bit)
declare OS
OS=$(operating_system)
ARCH=$(uname -m)
case $ARCH in
"x86_64")
ARCHITECTURE="${ARCHITECTURE}_amd64"
OS="${OS}_amd64"
;;
"i686" | "i386")
ARCHITECTURE="${ARCHITECTURE}_386"
OS="${OS}_386"
;;
*)
echo_error "Talisman currently only supports x86 and x86_64 architectures."
Expand All @@ -117,8 +120,8 @@ function run() {
;;
esac

TALISMAN_BINARY_NAME="talisman_${ARCHITECTURE}"
if [[ "$OS" == *"MINGW32_NT-10.0-WOW"* || "$OS" == *"MINGW64_NT-10.0"* ]]; then
TALISMAN_BINARY_NAME="talisman_${OS}"
if [[ $OS == *"windows"* ]]; then
TALISMAN_BINARY_NAME="${TALISMAN_BINARY_NAME}.exe"
fi
}
Expand Down Expand Up @@ -208,9 +211,9 @@ function run() {
mkdir -p "$TEMPLATE_DIR/hooks"
echo "Setting up template ${HOOK_SCRIPT} hook"

OS=$(uname -s)
OS=$(operating_system)
case $OS in
"MINGW32_NT-10.0-WOW" | "MINGW64_NT-10.0")
"windows")
TEMPLATE_DIR_WIN=$(sed -e 's/\/\([a-z]\)\//\1:\\/' -e 's/\//\\/g' <<<"$TEMPLATE_DIR")
TALISMAN_HOOK_SCRIPT_PATH_WIN=$(sed -e 's/\/\([a-z]\)\//\1:\\/' -e 's/\//\\/g' <<<"$TALISMAN_HOOK_SCRIPT_PATH")
cmd <<<"mklink "$TEMPLATE_DIR_WIN\\hooks\\$HOOK_SCRIPT" "$TALISMAN_HOOK_SCRIPT_PATH_WIN"" >/dev/null
Expand Down Expand Up @@ -288,13 +291,17 @@ function run() {
# set interactive mode for talisman if user opts in for it
# default to non-interactive mode
TALISMAN_INTERACTIVE_OPTION="false"
echo -e "\n\nSetting up interaction mode"
OS=$(operating_system)
if [[ $OS != "windows" ]]
then
echo -e "\n\nSetting up interaction mode"

read -rep $'\nDO YOU WANT TO BE PROMPTED WHEN ADDING EXCEPTIONS TO .talismanrc FILE? \nEnter y to install in interactive mode. Press any key to continue without interactive mode (y/n):' INTERACTIVE_OPT
if [[ $INTERACTIVE_OPT =~ ^[Yy]$ ]]
then
TALISMAN_INTERACTIVE_OPTION="true"
fi
fi
}

function set_talisman_home_and_binary_path() {
Expand Down Expand Up @@ -344,9 +351,9 @@ function run() {

NUMBER_OF_EXCEPTION_REPOS=$(cat ${EXCEPTIONS_FILE} | wc -l)

OS=$(uname -s)
OS=$(operating_system)
if [ ${NUMBER_OF_EXCEPTION_REPOS} -gt 0 ]; then
if [[ "$OS" == "MINGW32_NT-10.0-WOW" || "$OS" == "MINGW64_NT-10.0" ]]; then
if [[ $OS == "windows" ]]; then

EXCEPTIONS_FILE_HOME_PATH="${HOME}/talisman_missed_repositories.paths"
mv ${EXCEPTIONS_FILE} ${EXCEPTIONS_FILE_HOME_PATH}
Expand Down
55 changes: 29 additions & 26 deletions global_install_scripts/update_talisman.bash
Original file line number Diff line number Diff line change
Expand Up @@ -55,38 +55,41 @@ function run() {
cat ${TEMP_DIR}/download_urls
}

function operating_system() {
OS=$(uname -s)
case $OS in
"Linux")
echo "linux"
;;
"Darwin")
echo "darwin"
;;
MINGW32_NT-10.0-WOW*)
echo "windows"
;;
MINGW64_NT-10.0*)
echo "windows"
;;
*)
echo_error "Talisman currently only supports Windows, Linux and MacOS(darwin) systems."
echo_error "If this is a problem for you, please open an issue: https://github.com/${INSTALL_ORG_REPO}/issues/new"
exit $E_UNSUPPORTED_ARCH
;;
esac
}

function set_talisman_binary_name() {
# based on OS (linux/darwin) and ARCH(32/64 bit)
echo_debug "Running set_talisman_binary_name"
declare ARCHITECTURE
OS=$(uname -s)
case $OS in
"Linux")
ARCHITECTURE="linux"
;;
"Darwin")
ARCHITECTURE="darwin"
;;
"MINGW32_NT-10.0-WOW")
ARCHITECTURE="windows"
;;
"MINGW64_NT-10.0")
ARCHITECTURE="windows"
;;
*)
echo_error "Talisman currently only supports Windows, Linux and MacOS(darwin) systems."
echo_error "If this is a problem for you, please open an issue: https://github.com/${INSTALL_ORG_REPO}/issues/new"
exit $E_UNSUPPORTED_ARCH
;;
esac

declare OS
OS=$(operating_system)
ARCH=$(uname -m)
case $ARCH in
"x86_64")
ARCHITECTURE="${ARCHITECTURE}_amd64"
OS="${OS}_amd64"
;;
"i686" | "i386")
ARCHITECTURE="${ARCHITECTURE}_386"
OS="${OS}_386"
;;
*)
echo_error "Talisman currently only supports x86 and x86_64 architectures."
Expand All @@ -95,8 +98,8 @@ function run() {
;;
esac

TALISMAN_BINARY_NAME="talisman_${ARCHITECTURE}"
if [[ "$OS" == "MINGW32_NT-10.0-WOW" || "$OS" == "MINGW64_NT-10.0" ]]; then
TALISMAN_BINARY_NAME="talisman_${OS}"
if [[ $OS == *"windows"* ]]; then
TALISMAN_BINARY_NAME="${TALISMAN_BINARY_NAME}.exe"
fi
}
Expand Down

0 comments on commit 7e0ea2e

Please sign in to comment.