lib/phoenix-cli/cli.rb in phoenix-cli-0.0.3 vs lib/phoenix-cli/cli.rb in phoenix-cli-0.0.4

- old
+ new

@@ -39,15 +39,33 @@ def migrate exec("mix ecto.migrate") end desc "generate", "Run generators" - def generate(generator, resource_name, *args) - if generator == 'scaffold' - commands = args.join(' ') - exec("mix phoenix.gen.html #{resource_name.camelize} #{resource_name.pluralize} #{commands}") + def generate(*commands) + generator = commands[0] + resource = commands[1] + attributes = commands[2..(commands.length - 1)] + + resource_camelized = resource.camelize + resource_pluralized = resource.pluralize + + if ['scaffold', 'html', 'resource'].include? generator + exec("mix phoenix.gen.html #{resource_camelized} #{resource_pluralized} #{attributes.join(' ')}") end + + if ['json', 'api'].include? generator + exec("mix phoenix.json #{resource_camelized} #{resource_pluralized} #{attributes.join(' ')}") + end + + if ['channel', 'presence', 'secret', 'digest'].include? generator + exec("mix phoenix.gen.#{generator} #{attributes.join(' ')}") + end + + if ['model'].include? generator + exec("mix phoenix.gen.#{generator} #{resource_camelized} #{resource_pluralized} #{attributes.join(' ')}") + end end desc "routes", "Show phoenix routes" def routes exec("mix phoenix.routes") @@ -55,7 +73,11 @@ desc 'version', 'phoenix-cli version' def version puts PhoenixCli::VERSION end + end + + class Generate < Thor + end end