github.com/fnproject/cli@v0.0.0-20240508150455-e5d88bd86117/commands/commands.go (about)

     1  /*
     2   * Copyright (c) 2019, 2020 Oracle and/or its affiliates. All rights reserved.
     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 commands
    18  
    19  import (
    20  	"sort"
    21  
    22  	"github.com/fnproject/cli/common"
    23  	"github.com/fnproject/cli/objects/app"
    24  	"github.com/fnproject/cli/objects/context"
    25  	"github.com/fnproject/cli/objects/fn"
    26  	"github.com/fnproject/cli/objects/server"
    27  	"github.com/fnproject/cli/objects/trigger"
    28  	"github.com/urfave/cli"
    29  )
    30  
    31  //Cmd is a mapping from a commands name to its corresponding structure
    32  type Cmd map[string]cli.Command
    33  
    34  // Commands map of all top-level commands
    35  var Commands = Cmd{
    36  	"build":        BuildCommand(),
    37  	"build-server": BuildServerCommand(),
    38  	"bump":         common.BumpCommand(),
    39  	"invoke":       InvokeCommand(),
    40  	"configure":    ConfigureCommand(),
    41  	"create":       CreateCommand(),
    42  	"delete":       DeleteCommand(),
    43  	"deploy":       DeployCommand(),
    44  	"get":          GetCommand(),
    45  	"init":         InitCommand(),
    46  	"inspect":      InspectCommand(),
    47  	"list":         ListCommand(),
    48  	"migrate":      MigrateCommand(),
    49  	"push":         PushCommand(),
    50  	"start":        StartCommand(),
    51  	"stop":         StopCommand(),
    52  	"unset":        UnsetCommand(),
    53  	"update":       UpdateCommand(),
    54  	"use":          UseCommand(),
    55  }
    56  
    57  var CreateCmds = Cmd{
    58  	"apps":      app.Create(),
    59  	"functions": fn.Create(),
    60  	"triggers":  trigger.Create(),
    61  	"context":   context.Create(),
    62  }
    63  
    64  var ConfigCmds = Cmd{
    65  	"apps":      app.SetConfig(),
    66  	"functions": fn.SetConfig(),
    67  }
    68  
    69  var ConfigListCmds = Cmd{
    70  	"apps":      app.ListConfig(),
    71  	"functions": fn.ListConfig(),
    72  }
    73  
    74  var ConfigGetCmds = Cmd{
    75  	"apps":      app.GetConfig(),
    76  	"functions": fn.GetConfig(),
    77  }
    78  
    79  var ConfigSetCmds = Cmd{
    80  	"apps":      app.SetConfig(),
    81  	"functions": fn.SetConfig(),
    82  }
    83  
    84  var ConfigUnsetCmds = Cmd{
    85  	"apps":      app.UnsetConfig(),
    86  	"functions": fn.UnsetConfig(),
    87  }
    88  
    89  var DeleteCmds = Cmd{
    90  	"apps":      app.Delete(),
    91  	"functions": fn.Delete(),
    92  	"context":   context.Delete(),
    93  	"triggers":  trigger.Delete(),
    94  	"config":    ConfigCommand("delete"),
    95  }
    96  
    97  var GetCmds = Cmd{
    98  	"config": ConfigCommand("get"),
    99  }
   100  
   101  var InspectCmds = Cmd{
   102  	"apps":      app.Inspect(),
   103  	"context":   context.Inspect(),
   104  	"functions": fn.Inspect(),
   105  	"triggers":  trigger.Inspect(),
   106  }
   107  
   108  var ListCmds = Cmd{
   109  	"config":    ConfigCommand("list"),
   110  	"apps":      app.List(),
   111  	"functions": fn.List(),
   112  	"triggers":  trigger.List(),
   113  	"contexts":  context.List(),
   114  }
   115  
   116  var UnsetCmds = Cmd{
   117  	"config":  ConfigCommand("unset"),
   118  	"context": context.Unset(),
   119  }
   120  
   121  var UpdateCmds = Cmd{
   122  	"apps":      app.Update(),
   123  	"functions": fn.Update(),
   124  	"context":   context.Update(),
   125  	"server":    server.Update(),
   126  	"trigger":   trigger.Update(),
   127  }
   128  
   129  var UseCmds = Cmd{
   130  	"context": context.Use(),
   131  }
   132  
   133  // GetCommands returns a list of cli.commands
   134  func GetCommands(commands map[string]cli.Command) []cli.Command {
   135  	cmds := []cli.Command{}
   136  	for _, cmd := range commands {
   137  		cmds = append(cmds, cmd)
   138  	}
   139  
   140  	sort.Sort(cli.CommandsByName(cmds))
   141  	return cmds
   142  }