Skip to content

Commit 88205d2

Browse files
committed
Updated author information
1 parent 2fb13f8 commit 88205d2

File tree

1 file changed

+43
-39
lines changed

1 file changed

+43
-39
lines changed

bin/new.py

+43-39
Original file line numberDiff line numberDiff line change
@@ -29,41 +29,45 @@ def get_args() -> Args:
2929
"""Get arguments"""
3030

3131
parser = argparse.ArgumentParser(
32-
description='Create Python argparse program',
33-
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
32+
description="Create Python argparse program",
33+
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
34+
)
3435

3536
defaults = get_defaults()
36-
username = os.getenv('USER') or 'Anonymous'
37-
hostname = os.getenv('HOSTNAME') or 'localhost'
38-
39-
parser.add_argument('program', help='Program name', type=str)
40-
41-
parser.add_argument('-n',
42-
'--name',
43-
type=str,
44-
default=defaults.get('name', username),
45-
help='Name for docstring')
46-
47-
parser.add_argument('-e',
48-
'--email',
49-
type=str,
50-
default=defaults.get('email', f'{username}@{hostname}'),
51-
help='Email for docstring')
52-
53-
parser.add_argument('-p',
54-
'--purpose',
55-
type=str,
56-
default=defaults.get('purpose', 'Rock the Casbah'),
57-
help='Purpose for docstring')
58-
59-
parser.add_argument('-f',
60-
'--force',
61-
help='Overwrite existing',
62-
action='store_true')
37+
username = os.getenv("USER") or "Luke McGuire"
38+
39+
40+
parser.add_argument("program", help="Program name", type=str)
41+
42+
parser.add_argument(
43+
"-n",
44+
"--name",
45+
type=str,
46+
default=defaults.get("name", username),
47+
help="Name for docstring",
48+
)
49+
50+
parser.add_argument(
51+
"-e",
52+
"--email",
53+
type=str,
54+
default=defaults.get("email", email),
55+
help="Email for docstring",
56+
)
57+
58+
parser.add_argument(
59+
"-p",
60+
"--purpose",
61+
type=str,
62+
default=defaults.get("purpose", "Rock the Casbah"),
63+
help="Purpose for docstring",
64+
)
65+
66+
parser.add_argument("-f", "--force", help="Overwrite existing", action="store_true")
6367

6468
args = parser.parse_args()
6569

66-
args.program = args.program.strip().replace('-', '_')
70+
args.program = args.program.strip().replace("-", "_")
6771

6872
if not args.program:
6973
parser.error(f'Not a usable filename "{args.program}"')
@@ -80,20 +84,20 @@ def main() -> None:
8084

8185
if os.path.isfile(program) and not args.overwrite:
8286
answer = input(f'"{program}" exists. Overwrite? [yN] ')
83-
if not answer.lower().startswith('y'):
84-
sys.exit('Will not overwrite. Bye!')
87+
if not answer.lower().startswith("y"):
88+
sys.exit("Will not overwrite. Bye!")
8589

86-
print(body(args), file=open(program, 'wt'), end='')
90+
print(body(args), file=open(program, "wt"), end="")
8791

88-
if platform.system() != 'Windows':
89-
subprocess.run(['chmod', '+x', program], check=True)
92+
if platform.system() != "Windows":
93+
subprocess.run(["chmod", "+x", program], check=True)
9094

9195
print(f'Done, see new script "{program}."')
9296

9397

9498
# --------------------------------------------------
9599
def body(args: Args) -> str:
96-
""" The program template """
100+
"""The program template"""
97101

98102
today = str(date.today())
99103

@@ -176,11 +180,11 @@ def main():
176180
def get_defaults():
177181
"""Get defaults from ~/.new.py"""
178182

179-
rc = os.path.join(str(Path.home()), '.new.py')
183+
rc = os.path.join(str(Path.home()), ".new.py")
180184
defaults = {}
181185
if os.path.isfile(rc):
182186
for line in open(rc):
183-
match = re.match('([^=]+)=([^=]+)', line)
187+
match = re.match("([^=]+)=([^=]+)", line)
184188
if match:
185189
key, val = map(str.strip, match.groups())
186190
if key and val:
@@ -190,5 +194,5 @@ def get_defaults():
190194

191195

192196
# --------------------------------------------------
193-
if __name__ == '__main__':
197+
if __name__ == "__main__":
194198
main()

0 commit comments

Comments
 (0)