Skip to content

Commit

Permalink
add no_color flag
Browse files Browse the repository at this point in the history
  • Loading branch information
callmecampos committed Jun 5, 2020
1 parent 0f8f8b6 commit 0379103
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
20 changes: 15 additions & 5 deletions twine/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import argparse
import sys
from typing import Any

Expand All @@ -23,15 +24,24 @@


def main() -> Any:
colorama.init()
try:
return cli.dispatch(sys.argv[1:])
except (exceptions.TwineException, requests.HTTPError) as exc:
# somehow parse args here
parser = argparse.ArgumentParser()
parser.add_argument(
"--no_color", default=False, required=False, action="store_true",
)

args, _ = parser.parse_known_args(sys.argv[1:])

pre_style, post_style = "", ""
if not args.no_color:
colorama.init()
pre_style, post_style = colorama.Fore.RED, colorama.Style.RESET_ALL

return "{}{}: {}{}".format(
colorama.Fore.RED,
exc.__class__.__name__,
exc.args[0],
colorama.Style.RESET_ALL,
pre_style, exc.__class__.__name__, exc.args[0], post_style,
)


Expand Down
7 changes: 7 additions & 0 deletions twine/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,13 @@ def register_argparse_arguments(parser: argparse.ArgumentParser) -> None:
action="store_true",
help="Disable the progress bar.",
)
parser.add_argument(
"--no_color",
default=False,
required=False,
action="store_true",
help="Disable colored output.",
)

@classmethod
def from_argparse(cls, args: argparse.Namespace) -> "Settings":
Expand Down

0 comments on commit 0379103

Please sign in to comment.