(c *cli.Context)
| 230 | } |
| 231 | |
| 232 | func TunnelCommand(c *cli.Context) error { |
| 233 | sc, err := newSubcommandContext(c) |
| 234 | if err != nil { |
| 235 | return err |
| 236 | } |
| 237 | |
| 238 | // Run an adhoc named tunnel |
| 239 | // Allows for the creation, routing (optional), and startup of a tunnel in one command |
| 240 | // --name required |
| 241 | // --url or --hello-world required |
| 242 | // --hostname optional |
| 243 | if name := c.String(cfdflags.Name); name != "" { |
| 244 | hostname, err := validation.ValidateHostname(c.String("hostname")) |
| 245 | if err != nil { |
| 246 | return errors.Wrap(err, "Invalid hostname provided") |
| 247 | } |
| 248 | tunnelURL := c.String("url") |
| 249 | if tunnelURL == hostname && tunnelURL != "" && hostname != "" { |
| 250 | return fmt.Errorf("hostname and url shouldn't match. See --help for more information") |
| 251 | } |
| 252 | |
| 253 | return runAdhocNamedTunnel(sc, name, c.String(CredFileFlag)) |
| 254 | } |
| 255 | |
| 256 | // Run a quick tunnel |
| 257 | // A unauthenticated named tunnel hosted on <random>.<quick-tunnels-service>.com |
| 258 | shouldRunQuickTunnel := c.IsSet("url") || c.IsSet(ingress.HelloWorldFlag) |
| 259 | if c.String("quick-service") != "" && shouldRunQuickTunnel { |
| 260 | return RunQuickTunnel(sc) |
| 261 | } |
| 262 | |
| 263 | // If user provides a config, check to see if they meant to use `tunnel run` instead |
| 264 | if ref := config.GetConfiguration().TunnelID; ref != "" { |
| 265 | return fmt.Errorf("use `cloudflared tunnel run` to start tunnel %s", ref) |
| 266 | } |
| 267 | |
| 268 | // Classic tunnel usage is no longer supported |
| 269 | if c.String("hostname") != "" { |
| 270 | return errDeprecatedClassicTunnel |
| 271 | } |
| 272 | |
| 273 | return errors.New(tunnelCmdErrorMessage) |
| 274 | } |
| 275 | |
| 276 | func Init(info *cliutil.BuildInfo, gracefulShutdown chan struct{}) { |
| 277 | buildInfo, graceShutdownC = info, gracefulShutdown |
no test coverage detected