Skip to content

Commit e50245f

Browse files
authored
Automatically initialize the Git REPL mode when you do using GitRepl (#6)
1 parent 8880ff2 commit e50245f

File tree

2 files changed

+43
-12
lines changed

2 files changed

+43
-12
lines changed

src/GitRepl.jl

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import ReplMaker
55

66
export gitrepl
77

8-
const GIT_REPL_MODE_NAME = "GitRepl.jl Git REPL mode"
8+
const GIT_REPL_MODE_NAME = "GitRepl.jl Git REPL mode"
99
const GIT_REPL_MODE_PROMPT_TEXT = "git> "
10-
const GIT_REPL_MODE_START_KEY = ','
10+
const GIT_REPL_MODE_START_KEY = ','
1111

1212
function _gitrepl_parser(repl_input::AbstractString)
1313
return quote
@@ -17,18 +17,49 @@ function _gitrepl_parser(repl_input::AbstractString)
1717
end
1818
end
1919

20-
function gitrepl(; mode_name = GIT_REPL_MODE_NAME,
21-
prompt_text = GIT_REPL_MODE_PROMPT_TEXT,
22-
start_key = GIT_REPL_MODE_START_KEY,
20+
"""
21+
gitrepl(; kwargs...)
22+
23+
Set up the Git REPL mode.
24+
25+
## Optional keyword arguments
26+
27+
| Name | Type | Default Value |
28+
|:------------- | :--------------- |:-------------------------------------|
29+
| `mode_name` | `AbstractString` | `$(repr(GIT_REPL_MODE_NAME))` |
30+
| `prompt_text` | `AbstractString` | `$(repr(GIT_REPL_MODE_PROMPT_TEXT))` |
31+
| `start_key` | `AbstractChar` | `$(repr(GIT_REPL_MODE_START_KEY))` |
32+
33+
## Descriptions of optional keyword arguments:
34+
35+
| Name | Description |
36+
|:------------- | :-------------------------------------------------- |
37+
| `mode_name` | Name of the REPL mode |
38+
| `prompt_text` | Prompt text to display when the REPL mode is active |
39+
| `start_key` | Key to press to enter the REPL mode |
40+
41+
"""
42+
function gitrepl(; mode_name::AbstractString = GIT_REPL_MODE_NAME,
43+
prompt_text::AbstractString = GIT_REPL_MODE_PROMPT_TEXT,
44+
start_key::AbstractChar = GIT_REPL_MODE_START_KEY,
2345
kwargs...)
2446
ReplMaker.initrepl(
2547
_gitrepl_parser;
26-
mode_name = mode_name,
27-
prompt_text = prompt_text,
28-
start_key = start_key,
29-
kwargs...,
48+
mode_name,
49+
prompt_text,
50+
start_key,
51+
kwargs...
3052
)
3153
return nothing
3254
end
3355

56+
function __init__()
57+
try
58+
gitrepl()
59+
catch ex
60+
@error("", exception=(ex, catch_backtrace()))
61+
end
62+
return nothing
63+
end
64+
3465
end # module

test/runtests.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ using GitRepl
22
using Test
33

44
function withtempdir(f::Function)
5-
original_directory = pwd()
65
mktempdir() do tmp_dir
7-
return f(tmp_dir)
6+
cd(tmp_dir) do
7+
f(tmp_dir)
8+
end
89
end
9-
cd(original_directory)
1010
return nothing
1111
end
1212

0 commit comments

Comments
 (0)