@@ -55,6 +55,42 @@ func basicAuth(username, password string) string {
5555 return base64 .StdEncoding .EncodeToString ([]byte (auth ))
5656}
5757
58+ func appExists (name string ) {
59+ req := graphql .NewRequest (`
60+ query apps($name: String!, $allApps: Boolean!) {
61+ apps(name: $name, allApps: $allApps) {
62+ apps {
63+ name
64+ }
65+ }
66+ }
67+ ` )
68+
69+ req .Var ("allApps" , false )
70+ req .Var ("name" , name )
71+
72+ req .Header .Set ("Cache-Control" , "no-cache" )
73+ req .Header .Set ("Authorization" , "Basic " + basicAuth (Username , ApiKey ))
74+
75+ ctx := context .Background ()
76+
77+ var respData AppsResponse
78+
79+ client , err := graphqlClient ()
80+ if err != nil {
81+ log .Fatal (err )
82+ }
83+ if err := client .Run (ctx , req , & respData ); err != nil {
84+ log .Fatal (err )
85+ }
86+ for _ , app := range respData .AppsWrapper .Apps {
87+ fmt .Printf ("%v exists\n " , app .Name )
88+ os .Exit (0 )
89+ }
90+ fmt .Printf ("%v does not exist\n " , name )
91+ os .Exit (1 )
92+ }
93+
5894func appsList () {
5995 req := graphql .NewRequest (`
6096query apps($page: Int!, $allApps: Boolean!) {
@@ -218,6 +254,7 @@ func main() {
218254 appsListCmd := parser .NewCommand ("apps:list" , "List all apps" )
219255 appsCreateCmd := parser .NewCommand ("apps:create" , "Create an app" )
220256 appsDeleteCmd := parser .NewCommand ("apps:delete" , "Delete an app" )
257+ appExistsCmd := parser .NewCommand ("apps:exists" , "Check if an app exists" )
221258 err := parser .Parse (os .Args )
222259 if err != nil {
223260 fmt .Print (parser .Usage (err ))
@@ -230,6 +267,8 @@ func main() {
230267 appsCreate (* name )
231268 } else if appsDeleteCmd .Happened () {
232269 appsDelete (* name )
270+ } else if appExistsCmd .Happened () {
271+ appExists (* name )
233272 } else {
234273 err := fmt .Errorf ("bad arguments, please check usage" )
235274 fmt .Print (parser .Usage (err ))
0 commit comments