Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-shell
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-shell
Commits
f435c464
Commit
f435c464
authored
Sep 28, 2018
by
Nick Thomas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow the config directory to be specified
parent
7f1098a1
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
17 deletions
+31
-17
go/cmd/gitlab-shell/main.go
go/cmd/gitlab-shell/main.go
+17
-10
go/internal/config/config.go
go/internal/config/config.go
+13
-6
go/internal/config/config_test.go
go/internal/config/config_test.go
+1
-1
No files found.
go/cmd/gitlab-shell/main.go
View file @
f435c464
...
...
@@ -9,21 +9,28 @@ import (
"gitlab.com/gitlab-org/gitlab-shell/go/internal/config"
)
func
migrate
(
_cfg
*
config
.
Config
,
_args
[]
string
)
(
int
,
bool
)
{
// TODO: decide whether to handle the request in Go or not
var
(
binDir
string
rootDir
string
)
func
init
()
{
binDir
=
filepath
.
Dir
(
os
.
Args
[
0
])
rootDir
=
filepath
.
Dir
(
binDir
)
}
func
migrate
(
*
config
.
Config
)
(
int
,
bool
)
{
// TODO: Dispatch appropriate requests to Go handlers and return
// <exitstatus, true> depending on how they fare
return
0
,
false
}
// rubyExec will never return. It either replaces the current process with a
// Ruby interpreter, or outputs an error and kills the process.
func
execRuby
()
{
root
:=
filepath
.
Dir
(
os
.
Args
[
0
])
rubyCmd
:=
filepath
.
Join
(
root
,
"gitlab-shell-ruby"
)
rubyArgs
:=
os
.
Args
[
1
:
]
rubyEnv
:=
os
.
Environ
()
rubyCmd
:=
filepath
.
Join
(
binDir
,
"gitlab-shell-ruby"
)
execErr
:=
syscall
.
Exec
(
rubyCmd
,
rubyArgs
,
rubyEnv
)
execErr
:=
syscall
.
Exec
(
rubyCmd
,
os
.
Args
,
os
.
Environ
()
)
if
execErr
!=
nil
{
fmt
.
Fprintf
(
os
.
Stderr
,
"Failed to exec(%q): %v
\n
"
,
rubyCmd
,
execErr
)
os
.
Exit
(
1
)
...
...
@@ -33,14 +40,14 @@ func execRuby() {
func
main
()
{
// Fall back to Ruby in case of problems reading the config, but issue a
// warning as this isn't something we can sustain indefinitely
config
,
err
:=
config
.
New
(
)
config
,
err
:=
config
.
New
FromDir
(
rootDir
)
if
err
!=
nil
{
fmt
.
Fprintln
(
os
.
Stderr
,
"Failed to read config, falling back to gitlab-shell-ruby"
)
execRuby
()
}
// Try to handle the command with the Go implementation
if
exitCode
,
done
:=
migrate
(
config
,
os
.
Args
[
1
:
]
);
done
{
if
exitCode
,
done
:=
migrate
(
config
);
done
{
os
.
Exit
(
exitCode
)
}
...
...
go/internal/config/config.go
View file @
f435c464
...
...
@@ -26,24 +26,31 @@ type Config struct {
}
func
New
()
(
*
Config
,
error
)
{
cfg
:=
Config
{}
dir
,
err
:=
os
.
Getwd
()
if
err
!=
nil
{
return
nil
,
err
}
cfg
.
RootDir
=
dir
configBytes
,
err
:=
ioutil
.
ReadFile
(
path
.
Join
(
cfg
.
RootDir
,
configFile
))
return
NewFromDir
(
dir
)
}
func
NewFromDir
(
dir
string
)
(
*
Config
,
error
)
{
return
newFromFile
(
path
.
Join
(
dir
,
configFile
))
}
func
newFromFile
(
filename
string
)
(
*
Config
,
error
)
{
cfg
:=
&
Config
{
RootDir
:
path
.
Dir
(
filename
)}
configBytes
,
err
:=
ioutil
.
ReadFile
(
filename
)
if
err
!=
nil
{
return
nil
,
err
}
if
err
:=
parseConfig
(
configBytes
,
&
cfg
);
err
!=
nil
{
if
err
:=
parseConfig
(
configBytes
,
cfg
);
err
!=
nil
{
return
nil
,
err
}
return
&
cfg
,
nil
return
cfg
,
nil
}
// parseConfig expects YAML data in configBytes and a Config instance with RootDir set.
...
...
go/internal/config/config_test.go
View file @
f435c464
...
...
@@ -6,7 +6,7 @@ import (
"testing"
)
func
Test
ConfigLogFile
(
t
*
testing
.
T
)
{
func
Test
ParseConfig
(
t
*
testing
.
T
)
{
testRoot
:=
"/foo/bar"
testCases
:=
[]
struct
{
yaml
string
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment