Skip to content

Commit a629f41

Browse files
authored
Add host option (#160)
* remove spaces between badges * Add host option * all the hosts
1 parent 0d72326 commit a629f41

File tree

4 files changed

+24
-18
lines changed

4 files changed

+24
-18
lines changed

README.md

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,10 @@
33
Two-column web-based git difftool.
44

55
<p align="center">
6-
<a href="https://pypi.org/project/webdiff/" target="_blank">
7-
<img alt="PyPI - Version" src="https://img.shields.io/pypi/v/webdiff">
8-
</a>
9-
<a href="https://dl.circleci.com/status-badge/redirect/gh/danvk/webdiff/tree/master" target="_blank">
10-
<img alt="CircleCI 📝" src="https://dl.circleci.com/status-badge/img/gh/danvk/webdiff/tree/master.svg?style=svg">
11-
</a>
12-
<a href="https://github.com/danvk/webdiff/blob/master/LICENSE" target="_blank">
13-
<img alt="License: Apache2 📝" src="https://img.shields.io/github/license/danvk/webdiff">
14-
</a>
15-
<a href="https://github.com/sponsors/danvk" target="_blank">
16-
<img alt="Sponsor: On GitHub 💸" src="https://img.shields.io/badge/sponsor-on_github_💸-21bb42.svg" />
17-
</a>
6+
<a href="https://pypi.org/project/webdiff/" target="_blank"><img alt="PyPI - Version" src="https://img.shields.io/pypi/v/webdiff" /></a>
7+
<a href="https://dl.circleci.com/status-badge/redirect/gh/danvk/webdiff/tree/master" target="_blank"><img alt="CircleCI 📝" src="https://dl.circleci.com/status-badge/img/gh/danvk/webdiff/tree/master.svg?style=svg" /></a>
8+
<a href="https://github.com/danvk/webdiff/blob/master/LICENSE" target="_blank"><img alt="License: Apache2 📝" src="https://img.shields.io/github/license/danvk/webdiff" /></a>
9+
<a href="https://github.com/sponsors/danvk" target="_blank"><img alt="Sponsor: On GitHub 💸" src="https://img.shields.io/badge/sponsor-on_github_💸-21bb42.svg" /></a>
1810
</p>
1911

2012
Features include:
@@ -90,7 +82,8 @@ Options are:
9082
| Setting | Default | Notes |
9183
| -------------- | ------------- | ------ |
9284
| webdiff.theme | googlecode | Syntax highlighting theme (see [themes] directory). |
93-
| webdiff.port | -1 | Port on which to serve webdiff. Default is random open port. This can be overridden with `--port`. |
85+
| webdiff.port | -1 | Port on which to serve webdiff. Default is random open port. This can be overridden with the `--port` command line flag or the `WEBDIFF_PORT` environment variable. |
86+
| webdiff.host | localhost | Host name on which to serve the webdiff UI. Use `0.0.0.0` to serve publicly. The special value `<hostname>` uses your computer's network name. This can be overridden with the `--host` command line flag or the `WEBDIFF_HOST` environment variable. |
9487
| webdiff.maxDiffWidth | 100 | Maximum length of lines in the diff display. After this width, lines will wrap. |
9588
| webdiff.unified | 8 | Lines of context to display by default (`git diff -U`) |
9689
| webdiff.extraDirDiffArgs | "" | Any extra arguments to pass to `git diff` when diffing directories. |

webdiff/app.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ def open_browser():
278278
global PORT
279279
global HOSTNAME
280280
global GIT_CONFIG
281-
if (not 'NO_OPEN_BROWSER' in app.config) and GIT_CONFIG['webdiff']['openBrowser']:
281+
if GIT_CONFIG['webdiff']['openBrowser']:
282282
if is_hot_reload():
283283
log.debug('Skipping browser open on reload')
284284
else:
@@ -294,8 +294,9 @@ def pick_a_port(args, webdiff_config):
294294
if 'port' in args:
295295
return args['port']
296296

297-
if os.environ.get('WEBDIFF_PORT'):
298-
return int(os.environ.get('WEBDIFF_PORT'))
297+
env_port = os.environ.get('WEBDIFF_PORT')
298+
if env_port:
299+
return int(env_port)
299300

300301
# gitconfig
301302
if webdiff_config['port'] != -1:
@@ -340,8 +341,12 @@ def run():
340341
sys.stderr.write('GitConfig: %s\n' % GIT_CONFIG)
341342

342343
PORT = pick_a_port(parsed_args, WEBDIFF_CONFIG)
343-
344-
if app.config.get('USE_HOSTNAME'):
344+
HOSTNAME = (
345+
parsed_args.get('host')
346+
or os.environ.get('WEBDIFF_HOST')
347+
or WEBDIFF_CONFIG['host']
348+
)
349+
if HOSTNAME == '<hostname>':
345350
_hostname = platform.node()
346351
# platform.node will return empty string if it can't find the hostname
347352
if not _hostname:

webdiff/argparser.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ def parse(args, version=None):
3131
"""Returns {port, dirs: [], files: [], pr: {owner, repo, number}}."""
3232
parser = argparse.ArgumentParser(description='Run webdiff.', usage=USAGE)
3333
parser.add_argument('--version', action='version', version='webdiff %s' % version)
34+
parser.add_argument(
35+
'--host', type=str,
36+
help="Host name on which to serve webdiff UI. Default is localhost.",
37+
default=None
38+
)
3439
parser.add_argument('--port', '-p', type=int, help="Port to run webdiff on.", default=-1)
3540
parser.add_argument(
3641
'dirs', type=str, nargs='+', help="Directories to diff, or a github pull request URL."
@@ -41,6 +46,8 @@ def parse(args, version=None):
4146
out = {}
4247
if args.port != -1:
4348
out['port'] = args.port
49+
if args.host:
50+
out['host'] = args.host
4451

4552
if len(args.dirs) > 2:
4653
raise UsageError('You must specify two files/dirs (got %d)' % len(args.dirs))

webdiff/options.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"extraFileDiffArgs": "",
1111
"openBrowser": True,
1212
"port": -1, # random
13+
"host": "localhost",
1314
"maxDiffWidth": 100,
1415
"theme": "googlecode",
1516
"maxLinesForSyntax": 10_000,

0 commit comments

Comments
 (0)