Skip to content

Commit

Permalink
Add the no output option (-q/--no-output)
Browse files Browse the repository at this point in the history
  • Loading branch information
Chikashi-Kato committed Oct 4, 2017
2 parents 9eb381e + 5c9486f commit 6d6790e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ usage: slacktee.sh [options]
-d, --cond-prefix prefix pattern This prefix is added to the message, if the specified Regex pattern matches the input.
You can specify this multiple times.
If more than one pattern matches, the latest matched pattern is used.
-q, --no-output Don't echo the input.
--config config_file Specify the location of the config file.
--setup Setup slacktee interactively.
```
Expand Down
25 changes: 21 additions & 4 deletions slacktee.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env bash


# https://github.com/course-hero/slacktee
# ------------------------------------------------------------
# Copyright 2017 Course Hero, Inc.
#
Expand Down Expand Up @@ -96,11 +98,12 @@ options:
-e, --field title value Add a field to the attachment. You can specify this multiple times.
-s, --short-field title value Add a short field to the attachment. You can specify this multiple times.
-o, --cond-color color pattern Change the attachment color if the specified Regex pattern matches the input.
You can specify this multile times.
You can specify this multiple times.
If more than one pattern matches, the latest matched pattern is used.
-d, --cond-prefix prefix pattern This prefix is added to the message, if the specified Regex pattern matches the input.
You can specify this multile times.
You can specify this multiple times.
If more than one pattern matches, the latest matched pattern is used.
-q, --no-output Don't echo the input.
--config config_file Specify the location of the config file.
--setup Setup slacktee interactively.
EOF
Expand Down Expand Up @@ -205,7 +208,11 @@ function send_message()

function process_line()
{
echo "$1"

# do not print message / line if -q option is specified
if [[ "$no_output" == "" ]]; then
echo "$1"
fi

# Escape special characters.
line=$(escape_string "$1")
Expand Down Expand Up @@ -250,7 +257,14 @@ function process_line()
if [[ -z "$text" ]]; then
text="$line"
else
text="$text\n$line"
# See https://api.slack.com/rtm#limits for details on character limits
local message="$text\n$line"
if [[ ${#message} -ge 4000 ]]; then
send_message "$text"
text="$line"
else
text="$text\n$line"
fi
fi
fi
}
Expand Down Expand Up @@ -393,6 +407,9 @@ function parse_args()
title="$1"
shift
;;
-q|--no-output)
no_output=1
;;
-d|--cond-prefix)
case "$1" in
-*|'')
Expand Down
7 changes: 7 additions & 0 deletions test/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,13 @@ echo '\\\\I\like\backslash\.\\\\' | $SLACKTEE '-t' 'Escape backslashes'
echo '"I am a double quote", it said.' | $SLACKTEE '-t' 'Escape double quote'
echo "I'm a single quote." | $SLACKTEE '-t' 'Escape single quote'

# Test 18: Suppress the output
echo "-- Suppress the standard output (-q) --"
cat $DATA | $SLACKTEE '-q' '-t' 'Suppress the standard output (-q)'

echo "-- Suppress the standard output (--no-output) --"
cat $DATA | $SLACKTEE '--no-output' '-t' 'Suppress the standard output (--no-output)'

echo "Test is done!"


0 comments on commit 6d6790e

Please sign in to comment.