Class: WebscraperFramework::CLI
- Inherits:
-
Object
- Object
- WebscraperFramework::CLI
- Defined in:
- lib/webscraper_framework/cli.rb
Instance Method Summary collapse
- #create_project ⇒ Object
- #goodbye ⇒ Object
-
#initialize(arguments) ⇒ CLI
constructor
A new instance of CLI.
- #prompt_input(message) ⇒ Object
- #start ⇒ Object
- #start_server ⇒ Object
Constructor Details
#initialize(arguments) ⇒ CLI
Returns a new instance of CLI.
10 11 12 |
# File 'lib/webscraper_framework/cli.rb', line 10 def initialize(arguments) @action = arguments[0] end |
Instance Method Details
#create_project ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/webscraper_framework/cli.rb', line 30 def create_project puts "Hello! Welcome Webscraper Framework (name not definitive, hahaha!)".green.bold puts "This is a work in progress... nothing works.".blue.bold puts "Type 'exit' to quit".red.bold project_name = nil while project_name == nil input = prompt_input("Choose a name for your project 🔥 ") if File.directory?("./#{input}") puts "A folder with that name already exists, choose another name:" else project_name = input end end `mkdir #{project_name}` if File.directory?("./#{project_name}") puts "#{"[Success]".green.bold} created directory!\t ./#{project_name}/" `mkdir #{project_name}/config` puts "#{"[Success]".green.bold} created directory!\t ./#{project_name}/config" else puts "Something went wrong. Exiting...".red.bold goodbye end File.open("./#{project_name}/Gemfile", "w") do |f| f.puts "source 'https://rubygems.org'" f.puts "gem 'webscraper_framework'" end puts "#{"[Success]".green.bold} created file!\t\t ./#{project_name}/Gemfile" File.open("./#{project_name}/config/wsfr.rb", "w") do |f| f.puts "" end puts "#{"[Success]".green.bold} created file!\t\t ./#{project_name}/config/wsfr.rb" end |
#goodbye ⇒ Object
87 88 89 90 |
# File 'lib/webscraper_framework/cli.rb', line 87 def goodbye puts "\nFarewell, traveler! May the wind take you somewhere new!".red.on_white.bold exit end |
#prompt_input(message) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/webscraper_framework/cli.rb', line 74 def prompt_input() input = nil # while true # user_input != "exit" input = Readline.readline(, true).strip goodbye if input.downcase === "exit" input = input.to_s # end return input end |
#start ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/webscraper_framework/cli.rb', line 14 def start if @action == "new" create_project elsif @action == "server" start_server else puts "Invalid command, exiting".red.on_white.bold puts "The only valid command is 'new'".green.on_white.bold end goodbye end |
#start_server ⇒ Object
26 27 28 |
# File 'lib/webscraper_framework/cli.rb', line 26 def start_server WebscraperFramework::Application.new end |