@@ -1109,29 +1109,43 @@ function b
1109
1109
end
1110
1110
1111
1111
function mc --description " go build and install a binary"
1112
- if test (count $argv ) -lt 1
1113
- echo " Usage: mc <binary-name>"
1114
- return 1
1112
+ set -l binary_name
1113
+
1114
+ # Check if an argument is provided
1115
+ if test (count $argv ) -eq 0
1116
+ # No argument provided, check for directories in cmd/
1117
+ set -l cmd_dirs (path filter -d cmd/* )
1118
+ set -l num_dirs (count $cmd_dirs )
1119
+
1120
+ if test $num_dirs -eq 1
1121
+ # Exactly one directory found, use it as the binary name
1122
+ set binary_name (basename $cmd_dirs [1])
1123
+ else
1124
+ # Zero or multiple directories found, prompt for binary name
1125
+ echo " Error: Please specify the binary name. Found $num_dirs directories in cmd/."
1126
+ return 1
1127
+ end
1128
+ else
1129
+ # Use the provided argument as the binary name
1130
+ set binary_name $argv [1]
1115
1131
end
1116
1132
1117
- set -l binary_name $argv [1]
1118
1133
set -l gopath (go env GOPATH)
1119
1134
1120
1135
# Build the binary locally
1121
- echo " Building $binary_name locally..."
1136
+ # echo "Building $binary_name locally..."
1122
1137
go build -o $binary_name ./cmd/$binary_name
1123
1138
if test $status -ne 0
1124
1139
echo " Build failed"
1125
1140
return 1
1126
1141
end
1127
1142
1128
1143
# Install the binary to $GOPATH/bin
1129
- echo " Installing $binary_name ..."
1144
+ # echo "Installing $binary_name..."
1130
1145
go install ./cmd/$binary_name
1131
1146
if test $status -ne 0
1132
1147
echo " Failed to install $binary_name "
1133
1148
return 1
1134
1149
end
1135
-
1136
- echo " $binary_name installed successfully to $gopath /bin"
1150
+ echo " ✔ $binary_name installed"
1137
1151
end
0 commit comments