|
| 1 | +/* |
| 2 | + Copyright 2020 Docker Compose CLI authors |
| 3 | +
|
| 4 | + Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + you may not use this file except in compliance with the License. |
| 6 | + You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | + Unless required by applicable law or agreed to in writing, software |
| 11 | + distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + See the License for the specific language governing permissions and |
| 14 | + limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package main |
| 18 | + |
| 19 | +import ( |
| 20 | + "fmt" |
| 21 | + "os" |
| 22 | + "time" |
| 23 | + |
| 24 | + "github.com/spf13/cobra" |
| 25 | +) |
| 26 | + |
| 27 | +func main() { |
| 28 | + cmd := &cobra.Command{ |
| 29 | + Short: "Compose Provider Example", |
| 30 | + Use: "demo", |
| 31 | + } |
| 32 | + cmd.AddCommand(composeCommand()) |
| 33 | + err := cmd.Execute() |
| 34 | + if err != nil { |
| 35 | + fmt.Fprintln(os.Stderr, err) |
| 36 | + os.Exit(1) |
| 37 | + } |
| 38 | +} |
| 39 | + |
| 40 | +func composeCommand() *cobra.Command { |
| 41 | + c := &cobra.Command{ |
| 42 | + Use: "compose EVENT", |
| 43 | + TraverseChildren: true, |
| 44 | + } |
| 45 | + c.PersistentFlags().String("project-name", "", "compose project name") // unused |
| 46 | + c.AddCommand(&cobra.Command{ |
| 47 | + Use: "up", |
| 48 | + Run: up, |
| 49 | + Args: cobra.ExactArgs(1), |
| 50 | + }) |
| 51 | + c.AddCommand(&cobra.Command{ |
| 52 | + Use: "down", |
| 53 | + Run: down, |
| 54 | + Args: cobra.ExactArgs(1), |
| 55 | + }) |
| 56 | + return c |
| 57 | +} |
| 58 | + |
| 59 | +func up(_ *cobra.Command, args []string) { |
| 60 | + servicename := args[0] |
| 61 | + for i := 0; i < 100; i += 10 { |
| 62 | + time.Sleep(1 * time.Second) |
| 63 | + fmt.Printf(`{ "type": "info", "message": "Processing ... %d%%" }\n`, i) |
| 64 | + } |
| 65 | + fmt.Printf(`{ "type": "setenv", "message": "URL=https://magic.cloud/%s" }\n`, servicename) |
| 66 | +} |
| 67 | + |
| 68 | +func down(_ *cobra.Command, _ []string) { |
| 69 | + fmt.Printf(`{ "type": "error", "message": "Permission error" }\n`) |
| 70 | +} |
0 commit comments