@@ -33,6 +33,7 @@ def services_args
33
33
[`sudo`] `brew services cleanup`:
34
34
Remove all unused services.
35
35
EOS
36
+ flag "--file=" , description : "Use the plist file from this location to start or run the service."
36
37
switch "--all" , description : "Run <subcommand> on all services."
37
38
end
38
39
end
@@ -42,9 +43,52 @@ def services
42
43
43
44
raise UsageError , "`brew services` is supported only on macOS!" unless OS . mac?
44
45
46
+ # pbpaste's exit status is a proxy for detecting the use of reattach-to-user-namespace
47
+ raise UsageError , "`brew services` cannot run under tmux!" if ENV [ "TMUX" ] && !quiet_system ( "/usr/bin/pbpaste" )
48
+
45
49
# Keep this after the .parse to keep --help fast.
46
50
require_relative "../lib/services_cli"
47
51
48
- Homebrew ::ServicesCli . run! ( args )
52
+ # Parse arguments.
53
+ subcommand , formula , custom_plist , = args . named
54
+
55
+ if custom_plist . present?
56
+ odeprecated "with file as last argument" , "`--file=` to specify a plist file"
57
+ else
58
+ custom_plist = args . file
59
+ end
60
+
61
+ if [ "list" , "cleanup" ] . include? ( subcommand )
62
+ raise UsageError , "The `#{ subcommand } ` subcommand does not accept a formula argument!" if formula
63
+ raise UsageError , "The `#{ subcommand } ` subcommand does not accept the --all argument!" if args . all?
64
+ end
65
+
66
+ target = if args . all?
67
+ available_services
68
+ elsif formula
69
+ Service . new ( Formulary . factory ( formula ) )
70
+ end
71
+
72
+ # Dispatch commands and aliases.
73
+ case subcommand . presence
74
+ when nil , "list" , "ls"
75
+ Homebrew ::ServicesCli . list
76
+ when "cleanup" , "clean" , "cl" , "rm"
77
+ Homebrew ::ServicesCli . cleanup
78
+ when "restart" , "relaunch" , "reload" , "r"
79
+ Homebrew ::ServicesCli . check ( target ) &&
80
+ Homebrew ::ServicesCli . restart ( target , custom_plist , verbose : args . verbose? )
81
+ when "run"
82
+ Homebrew ::ServicesCli . check ( target ) &&
83
+ Homebrew ::ServicesCli . run ( target )
84
+ when "start" , "launch" , "load" , "s" , "l"
85
+ Homebrew ::ServicesCli . check ( target ) &&
86
+ Homebrew ::ServicesCli . start ( target , custom_plist , verbose : args . verbose? )
87
+ when "stop" , "unload" , "terminate" , "term" , "t" , "u"
88
+ Homebrew ::ServicesCli . check ( target ) &&
89
+ Homebrew ::ServicesCli . stop ( target )
90
+ else
91
+ raise UsageError , "unknown subcommand: `#{ subcommand } `"
92
+ end
49
93
end
50
94
end
0 commit comments