gate-stack-cli 1.0.4 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/scripts/gate +110 -15
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gate-stack-cli",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "private": false,
5
5
  "description": "Gate CLI wrapper for git (gate clone/init/push/pull/status)",
6
6
  "bin": {
package/scripts/gate CHANGED
@@ -6,39 +6,85 @@
6
6
  # gate pull [args...]
7
7
  # gate push [args...]
8
8
  # gate status [args...]
9
+ # gate fetch [args...]
10
+ # gate checkout [args...]
11
+ # gate branch [args...]
12
+ # gate remote [args...]
13
+ # gate log [args...]
14
+ # gate commit [args...]
9
15
  # gate <qualquer-comando-git> [...]
10
16
 
11
17
  set -euo pipefail
12
18
 
13
19
  GATE_HOST="${GATE_HOST:-http://localhost:5000}"
14
20
  GIT_BIN="${GIT_BIN:-git}"
21
+ VERSION="1.0.5"
15
22
 
23
+ # ── Cores ─────────────────────────────────────────────────────────────
24
+ if [ -t 1 ]; then
25
+ R='\033[0;31m'; G='\033[0;32m'; Y='\033[1;33m'; B='\033[0;34m'
26
+ C='\033[0;36m'; W='\033[0;37m'; N='\033[0m'
27
+ else
28
+ R=''; G=''; Y=''; B=''; C=''; W=''; N=''
29
+ fi
30
+
31
+ info() { printf "${G}▸${N} %s\n" "$*"; }
32
+ warn() { printf "${Y}▸${N} %s\n" "$*" >&2; }
33
+ error() { printf "${R}✖${N} %s\n" "$*" >&2; }
34
+ header() { printf "\n${B}❯${N} %s\n" "$*"; }
35
+
36
+ # ── Versão ────────────────────────────────────────────────────────────
37
+ version() {
38
+ printf "gate-stack-cli %s\n" "$VERSION"
39
+ }
40
+
41
+ # ── Usage ─────────────────────────────────────────────────────────────
16
42
  usage() {
17
- cat <<'EOF'
18
- Gate CLI (wrapper para git)
19
- Usage:
20
- gate clone <slug|url> [dir]
21
- gate init [dir]
22
- gate pull [args...]
23
- gate push [args...]
24
- gate status [args...]
25
- gate <comando-git> [...]
26
-
27
- Env vars:
28
- GATE_HOST Base URL para o Git HTTP (default: http://localhost:5000)
43
+ cat <<EOF
44
+ Gate CLI (wrapper para git) v${VERSION}
45
+
46
+ ${B}Usage:${N}
47
+ gate clone <slug|url> [dir] Clona pelo slug ou URL completa
48
+ gate init [dir] Inicializa repositório local
49
+ gate pull [args...] git pull
50
+ gate push [args...] git push
51
+ gate status [args...] git status
52
+ gate <comando-git> [...] Pass-through para qualquer git
53
+
54
+ ${B}Aliases:${N}
55
+ st → status ci → commit
56
+ br → branch co → checkout
57
+ f → fetch rm → remote
58
+ lg → log
59
+
60
+ ${B}Opções:${N}
61
+ -h, --help, help Mostra esta ajuda
62
+ --version, -v Mostra versão
63
+
64
+ ${B}Env vars:${N}
65
+ GATE_HOST Base URL para o Git HTTP (default: ${GATE_HOST})
29
66
  GIT_BIN Caminho do binário git (default: git)
30
67
  EOF
31
68
  }
32
69
 
70
+ # ── Helpers ───────────────────────────────────────────────────────────
33
71
  ensure_args() {
34
- local count=$1
35
- shift
72
+ local count=$1; shift
36
73
  if [ $# -lt "$count" ]; then
37
74
  usage
38
75
  exit 1
39
76
  fi
40
77
  }
41
78
 
79
+ check_host() {
80
+ local url=$1
81
+ if command -v curl &>/dev/null; then
82
+ curl -sf --max-time 5 "$url" &>/dev/null || return 1
83
+ elif command -v wget &>/dev/null; then
84
+ wget -q --spider --timeout=5 "$url" 2>/dev/null || return 1
85
+ fi
86
+ }
87
+
42
88
  normalize_clone_url() {
43
89
  local target=$1
44
90
  if [[ "$target" =~ ^https?:// ]] || [[ "$target" =~ ^git@ ]] || [[ "$target" =~ ^ssh:// ]]; then
@@ -48,6 +94,7 @@ normalize_clone_url() {
48
94
  fi
49
95
  }
50
96
 
97
+ # ── Main ──────────────────────────────────────────────────────────────
51
98
  cmd="${1:-}"
52
99
  if [ -z "$cmd" ]; then
53
100
  usage
@@ -55,24 +102,72 @@ if [ -z "$cmd" ]; then
55
102
  fi
56
103
  shift || true
57
104
 
105
+ # --version
106
+ case "$cmd" in
107
+ -v|--version) version; exit 0 ;;
108
+ esac
109
+
110
+ # Aliases curtos
111
+ case "$cmd" in
112
+ st) cmd="status" ;;
113
+ ci) cmd="commit" ;;
114
+ br) cmd="branch" ;;
115
+ co) cmd="checkout" ;;
116
+ f) cmd="fetch" ;;
117
+ rm) if [ -z "${1:-}" ] || [[ "${1:-}" != ==* ]]; then cmd="remote"; fi ;;
118
+ lg) cmd="log" ;;
119
+ esac
120
+
58
121
  case "$cmd" in
59
122
  clone)
60
123
  ensure_args 1 "$@"
61
124
  url=$(normalize_clone_url "$1"); shift
62
- exec "$GIT_BIN" clone "$url" "$@"
125
+
126
+ base_url="${url%%/*}"
127
+ if check_host "$base_url"; then
128
+ info "Clonando de ${C}${url}${N} ..."
129
+ exec "$GIT_BIN" clone "$url" "$@"
130
+ else
131
+ error "Não foi possível conectar a ${R}${base_url}${N}"
132
+ error "Verifique GATE_HOST (atual: ${GATE_HOST})"
133
+ error "Use URL completa: gate clone https://..."
134
+ exit 1
135
+ fi
63
136
  ;;
64
137
  init)
138
+ info "Inicializando repositório"
65
139
  exec "$GIT_BIN" init "$@"
66
140
  ;;
67
141
  pull)
142
+ info "Pull"
68
143
  exec "$GIT_BIN" pull "$@"
69
144
  ;;
70
145
  push)
146
+ info "Push"
71
147
  exec "$GIT_BIN" push "$@"
72
148
  ;;
73
149
  status)
74
150
  exec "$GIT_BIN" status "$@"
75
151
  ;;
152
+ fetch)
153
+ info "Fetch"
154
+ exec "$GIT_BIN" fetch "$@"
155
+ ;;
156
+ checkout)
157
+ exec "$GIT_BIN" checkout "$@"
158
+ ;;
159
+ branch)
160
+ exec "$GIT_BIN" branch "$@"
161
+ ;;
162
+ remote)
163
+ exec "$GIT_BIN" remote "$@"
164
+ ;;
165
+ log)
166
+ exec "$GIT_BIN" log "$@"
167
+ ;;
168
+ commit)
169
+ exec "$GIT_BIN" commit "$@"
170
+ ;;
76
171
  -h|--help|help)
77
172
  usage
78
173
  ;;