diff --git a/tox/_quickstart.py b/tox/_quickstart.py
index 37c48ddc..bc283a8a 100644
--- a/tox/_quickstart.py
+++ b/tox/_quickstart.py
@@ -40,6 +40,7 @@
     OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 """
 
+import argparse
 import sys
 from os import path
 from codecs import open
@@ -224,19 +225,24 @@ def generate(d, overwrite=True, silent=False):
 
     def write_file(fpath, mode, content):
         print('Creating file %s.' % fpath)
-        f = open(fpath, mode, encoding='utf-8')
         try:
-            f.write(content)
-        finally:
-            f.close()
+            with open(fpath, mode, encoding='utf-8') as f:
+                f.write(content)
+        except IOError:
+            print('Error writing file.')
+            raise
 
     sys.stdout.write('\n')
 
-    fpath = 'tox.ini'
+    fpath = path.join(d.get('path', ''), 'tox.ini')
 
     if path.isfile(fpath) and not overwrite:
         print('File %s already exists.' % fpath)
-        do_prompt(d, 'fpath', 'Alternative path to write tox.ini contents to', 'tox-generated.ini')
+        do_prompt(
+            d,
+            'fpath',
+            'Alternative path to write tox.ini contents to',
+            path.join(d.get('path', ''), 'tox-generated.ini'))
         fpath = d['fpath']
 
     write_file(fpath, 'w', conf_text)
@@ -251,14 +257,25 @@ Execute `tox` to test your project.
 ''')
 
 
+def parse_args(argv):
+    parser = argparse.ArgumentParser(
+        description='Command-line script to quickly setup tox.ini for a Python project.'
+    )
+    parser.add_argument(
+        'root', type=str, nargs='?', default='.',
+        help='Custom root directory to write tox.ini to. Defaults to current directory.'
+    )
+    parser.add_argument('--version', action='version', version='%(prog)s ' + __version__)
+
+    args = argv[1:]
+    return parser.parse_args(args)
+
+
 def main(argv=sys.argv):
-    d = {}
+    args = parse_args(argv)
 
-    if len(argv) > 3:
-        print('Usage: tox-quickstart [root]')
-        sys.exit(1)
-    elif len(argv) == 2:
-        d['path'] = argv[1]
+    d = {}
+    d['path'] = args.root
 
     try:
         ask_user(d)
@@ -268,8 +285,13 @@ def main(argv=sys.argv):
         return
 
     d = process_input(d)
-    generate(d, overwrite=False)
+    try:
+        generate(d, overwrite=False)
+    except Exception:
+        return 2
+
+    return 0
 
 
 if __name__ == '__main__':
-    main()
+    sys.exit(main())

tox-quickstart should have a --help
- Bitbucket: https://bitbucket.org/hpk42/tox/issue/315
- Originally reported by: @warsaw
- Originally created at: 2016-02-16T16:16:47.537

and probably a --version too.

diff --git a/tests/test_quickstart.py b/tests/test_quickstart.py
index 49b2b0c0..76551008 100644
--- a/tests/test_quickstart.py
+++ b/tests/test_quickstart.py
@@ -379,6 +379,106 @@ deps =
         result = read_tox('tox-generated.ini')
         assert(result == expected_tox_ini)
 
+    def test_quickstart_main_tox_ini_location_can_be_overridden(
+            self,
+            tmpdir,
+            monkeypatch):
+        monkeypatch.setattr(
+            tox._quickstart, 'term_input',
+            self.get_mock_term_input(
+                [
+                    '1',          # py27 and py33
+                    'py.test',    # command to run tests
+                    '',            # test dependencies
+                ]
+            )
+        )
+
+        root_dir = tmpdir.mkdir('alt-root')
+        tox_ini_path = root_dir.join('tox.ini')
+
+        tox._quickstart.main(argv=['tox-quickstart', root_dir.basename])
+
+        assert tox_ini_path.isfile()
+
+        expected_tox_ini = """
+# Tox (https://tox.readthedocs.io/) is a tool for running tests
+# in multiple virtualenvs. This configuration file will run the
+# test suite on all supported python versions. To use it, "pip install tox"
+# and then run "tox" from this directory.
+
+[tox]
+envlist = py27
+
+[testenv]
+commands = py.test
+deps =
+    pytest
+""".lstrip()
+        result = read_tox(fname=tox_ini_path.strpath)
+        assert(result == expected_tox_ini)
+
+    def test_quickstart_main_custom_tox_ini_location_with_existing_tox_ini(
+            self,
+            tmpdir,
+            monkeypatch):
+        monkeypatch.setattr(
+            tox._quickstart, 'term_input',
+            self.get_mock_term_input(
+                [
+                    '1',          # py27 and py33
+                    'py.test',    # command to run tests
+                    '',            # test dependencies
+                    '',           # tox.ini already exists; overwrite?
+                ]
+            )
+        )
+
+        root_dir = tmpdir.mkdir('alt-root')
+        tox_ini_path = root_dir.join('tox.ini')
+        tox_ini_path.write('foo\nbar\n')
+
+        tox._quickstart.main(argv=['tox-quickstart', root_dir.basename])
+        tox_ini_path = root_dir.join('tox-generated.ini')
+
+        assert tox_ini_path.isfile()
+
+        expected_tox_ini = """
+# Tox (https://tox.readthedocs.io/) is a tool for running tests
+# in multiple virtualenvs. This configuration file will run the
+# test suite on all supported python versions. To use it, "pip install tox"
+# and then run "tox" from this directory.
+
+[tox]
+envlist = py27
+
+[testenv]
+commands = py.test
+deps =
+    pytest
+""".lstrip()
+        result = read_tox(fname=tox_ini_path.strpath)
+        assert(result == expected_tox_ini)
+
+    def test_quickstart_main_custom_nonexistent_tox_ini_location(
+            self,
+            tmpdir,
+            monkeypatch):
+        monkeypatch.setattr(
+            tox._quickstart, 'term_input',
+            self.get_mock_term_input(
+                [
+                    '1',          # py27 and py33
+                    'py.test',    # command to run tests
+                    '',           # test dependencies
+                ]
+            )
+        )
+
+        root_dir = tmpdir.join('nonexistent-root')
+
+        assert tox._quickstart.main(argv=['tox-quickstart', root_dir.basename]) == 2
+
 
 class TestToxQuickstart(object):
     def test_pytest(self):

pip install -e .[dev]
parse_log_pytest
pytest
pytest pytest-timeout
3.6
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
attrs @ file:///opt/conda/conda-bld/attrs_1642510447205/work
certifi==2021.5.30
distlib==0.3.9
filelock==3.4.1
importlib-metadata==4.8.3
importlib-resources==5.4.0
iniconfig @ file:///home/linux1/recipes/ci/iniconfig_1610983019677/work
more-itertools @ file:///tmp/build/80754af9/more-itertools_1637733554872/work
packaging @ file:///tmp/build/80754af9/packaging_1637314298585/work
platformdirs==2.4.0
pluggy @ file:///tmp/build/80754af9/pluggy_1615976315926/work
py @ file:///opt/conda/conda-bld/py_1644396412707/work
pyparsing @ file:///tmp/build/80754af9/pyparsing_1635766073266/work
pytest==6.2.4
pytest-timeout==2.1.0
toml @ file:///tmp/build/80754af9/toml_1616166611790/work
-e git+https://github.com/tox-dev/tox.git@682b96094b971b294c931c7464fbafe846308d4d#egg=tox
typing_extensions @ file:///opt/conda/conda-bld/typing_extensions_1647553014482/work
virtualenv==20.17.1
zipp @ file:///tmp/build/80754af9/zipp_1633618647012/work

name: tox
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - attrs=21.4.0=pyhd3eb1b0_0
  - ca-certificates=2025.2.25=h06a4308_0
  - certifi=2021.5.30=py36h06a4308_0
  - importlib_metadata=4.8.1=hd3eb1b0_0
  - iniconfig=1.1.1=pyhd3eb1b0_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.3=he6710b0_2
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - more-itertools=8.12.0=pyhd3eb1b0_0
  - ncurses=6.4=h6a678d5_0
  - openssl=1.1.1w=h7f8727e_0
  - packaging=21.3=pyhd3eb1b0_0
  - pip=21.2.2=py36h06a4308_0
  - pluggy=0.13.1=py36h06a4308_0
  - py=1.11.0=pyhd3eb1b0_0
  - pyparsing=3.0.4=pyhd3eb1b0_0
  - pytest=6.2.4=py36h06a4308_2
  - python=3.6.13=h12debd9_1
  - readline=8.2=h5eee18b_0
  - setuptools=58.0.4=py36h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - toml=0.10.2=pyhd3eb1b0_0
  - typing_extensions=4.1.1=pyh06a4308_0
  - wheel=0.37.1=pyhd3eb1b0_0
  - xz=5.6.4=h5eee18b_1
  - zipp=3.6.0=pyhd3eb1b0_0
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - distlib==0.3.9
      - filelock==3.4.1
      - importlib-metadata==4.8.3
      - importlib-resources==5.4.0
      - platformdirs==2.4.0
      - pytest-timeout==2.1.0
      - virtualenv==20.17.1
prefix: /opt/conda/envs/tox

tests/test_quickstart.py::TestToxQuickstartMain::test_quickstart_main_tox_ini_location_can_be_overridden tests/test_quickstart.py::TestToxQuickstartMain::test_quickstart_main_custom_tox_ini_location_with_existing_tox_ini tests/test_quickstart.py::TestToxQuickstartMain::test_quickstart_main_custom_nonexistent_tox_ini_location
tests/test_quickstart.py::TestToxQuickstartMain::test_quickstart_main_choose_individual_pythons_and_pytest tests/test_quickstart.py::TestToxQuickstartMain::test_quickstart_main_choose_individual_pythons_and_nose_adds_deps tests/test_quickstart.py::TestToxQuickstartMain::test_quickstart_main_choose_individual_pythons_and_trial_adds_deps tests/test_quickstart.py::TestToxQuickstartMain::test_quickstart_main_choose_individual_pythons_and_pytest_adds_deps tests/test_quickstart.py::TestToxQuickstartMain::test_quickstart_main_choose_py27_and_pytest_adds_deps tests/test_quickstart.py::TestToxQuickstartMain::test_quickstart_main_choose_py27_and_py33_and_pytest_adds_deps tests/test_quickstart.py::TestToxQuickstartMain::test_quickstart_main_choose_all_pythons_and_pytest_adds_deps tests/test_quickstart.py::TestToxQuickstartMain::test_quickstart_main_choose_individual_pythons_and_defaults tests/test_quickstart.py::TestToxQuickstartMain::test_quickstart_main_existing_tox_ini tests/test_quickstart.py::TestToxQuickstart::test_pytest tests/test_quickstart.py::TestToxQuickstart::test_setup_py_test tests/test_quickstart.py::TestToxQuickstart::test_trial tests/test_quickstart.py::TestToxQuickstart::test_nosetests
tox/_quickstart.py
tox/_quickstart.py