feat: use cobra to provide subcommands, move sources to lib (#506)

- Use cobra in order to provide subcommands `serve` and `db`.
  - Subdir `cmd` is removed.
  - Subdir `cli` is created, which is a standard cobra structure.
- Sources related to the core are moved to subdir `lib`.
- #497 and #504 are merged.
- Deprecated flags are added. See https://github.com/filebrowser/filebrowser/pull/497#discussion_r209428120.
- [`viper.BindPFlags`](https://godoc.org/github.com/spf13/viper#BindPFlags) is used in order to reduce the verbosity in `serve.go`.


Former-commit-id: 4b37ad82e91e01f7718cd389469814674bdf7032 [formerly c84d7fcf9c362b2aa1f9e5b57196152f53835e61] [formerly 2fef43c0382f3cc7d13e0297ccb467e38fac6982 [formerly 69a3f853bd2821d2c52a435277aaac68a468d39b]]
Former-commit-id: 2f7dc1b8ee6735382cedae2053f40c546c21de45 [formerly b438417178b47ad5f7caf9cb728f4a5011a09f5e]
Former-commit-id: 07bc58ab2e1ab10c30be8d0a5e760288bfc4d4dc
This commit is contained in:
1138-4EB
2018-08-21 22:42:03 +01:00
parent 93acf4a6f7
commit 0536d8342c
35 changed files with 535 additions and 840 deletions

View File

@@ -2,22 +2,19 @@
set -e
cd $(dirname $0)/..
cd $(dirname $0)/../cli
dep ensure -vendor-only
go get -v ./...
if [ "$COMMIT_SHA" != "" ]; then
echo "Set version to ($COMMIT_SHA)"
sed -i.bak "s|(untracked)|($COMMIT_SHA)|g" filebrowser.go
sed -i.bak "s|(untracked)|($COMMIT_SHA)|g" ../lib/filebrowser.go
fi
echo "Build cmd/filebrowser"
cd cmd/filebrowser
CGO_ENABLED=0 go build -a
cd ../..
cp cmd/filebrowser/filebrowser ./
CGO_ENABLED=0 go build -a -o filebrowser
if [ "$COMMIT_SHA" != "" ]; then
echo "Reset version to (untracked)"
sed -i "s|($COMMIT_SHA)|(untracked)|g" filebrowser.go
sed -i "s|($COMMIT_SHA)|(untracked)|g" ../lib/filebrowser.go
fi

View File

@@ -2,8 +2,8 @@
cd $(dirname $0)/..
if [ -d "rice-box.go" ]; then
rm -rf rice-box.go
if [ -d lib/"rice-box.go" ]; then
rm -rf lib/rice-box.go
fi
if [ "$USE_DOCKER" != "" ]; then
@@ -41,9 +41,8 @@ if [ "$USE_DOCKER" != "" ]; then
for d in "dist/" "node_modules/"; do
docker cp filebrowser-tmp:/$WDIR/frontend/$d frontend
done
for d in "vendor/" "rice-box.go" "filebrowser"; do
docker cp filebrowser-tmp:/$WDIR/$d ./
done
docker cp filebrowser-tmp:/$WDIR/cli/filebrowser ./filebrowser
docker cp filebrowser-tmp:/$WDIR/lib/rice-box.go ./lib/rice-box.go
fi
docker rm -f filebrowser-tmp
else

View File

@@ -19,4 +19,5 @@ if ! [ -x "$(command -v rice)" ]; then
fi
# Embed the assets using rice
cd lib
rice embed-go

View File

@@ -11,8 +11,8 @@ openssl aes-256-cbc -K $encrypted_9ca81b5594f5_key -iv $encrypted_9ca81b5594f5_i
git clone git@github.com:filebrowser/caddy caddy
cd caddy
cp ../../rice-box.go assets/
sed -i 's/package filebrowser/package assets/g' assets/rice-box.go
cp ../../lib/rice-box.go assets/
sed -i 's/package lib/package assets/g' assets/rice-box.go
git checkout -b update-rice-box origin/master
git config --local user.name "Filebrowser Bot"
git config --local user.email "FilebrowserBot@users.noreply.github.com"

View File

@@ -8,7 +8,7 @@ dolint='gometalinter --exclude="rice-box.go" --exclude="vendor" --deadline=300s
if [ "$USE_DOCKER" != "" ]; then
docker run --rm -itv $(pwd):/src filebrowser/dev sh -c "\
cp -r /src/. ./ && dep ensure -v -vendor-only && \
cp -r /src/. ./ && cd cli && go get -v ./... && \
CGO_ENABLED=0 $dolint"
else
$dolint