Debian Codegraph @

core/boot/option.rb

raw symbols SCIP
1 # -*- coding: utf-8 -*-
2 # コマンドラインオプションを受け取る
3
4 require 'optparse'
5
6 module Mopt
7 extend Mopt
8
9 @opts = {
10 error_level: 1 }
11
12 def confroot
13 @opts[:confroot] || ENV.fetch('MIKUTTER_CONFROOT') { File.join(Dir.home, '.mikutter') }
14 end
15
16 def method_missing(key)
17 scope = class << self; self end
18 scope.__send__(:define_method, key){ @opts[key.to_sym] }
19 @opts[key.to_sym] end
20
21 def parse(argv=ARGV, exec_command: false)
22 unless argv.is_a? OptionParser::Arguable
23 argv.extend(OptionParser::Arguable) end
24 OptionParser.new do |opt|
25 opt.banner = "Usage: mikutter.rb [options] [command]"
26 opt.separator "options are:"
27 opt.on('--debug', 'Debug mode (for development)') { |v|
28 @opts[:debug] = true
29 @opts[:error_level] = v.is_a?(Integer) ? v : 3 }
30 opt.on('--profile', 'Profiling mode (for development)') { @opts[:profile] = true }
31 opt.on('--skip-version-check', 'Skip library and environment version check') { @opts[:skip_version_check] = true }
32 opt.on('-p', '--plugin=', 'Load specified plugins and depended plugins (comma separated)'){ |plugins| @opts[:plugin] = (@opts[:plugin]||[]).concat plugins.split(",") }
33 opt.on('--confroot=', 'set confroot directory') { |v|
34 @opts[:confroot] = File.expand_path(v) }
35 opt.on('--daemon', '-d'){
36 Process.daemon(true) }
37 opt.on('--color', 'Colorize terminal output') { @opts[:color] = !Gem.win_platform? }
38 opt.on('--clean', 'delete all caches and duplicated files') { |v|
39 require 'fileutils'
40 require_relative '../utils'
41 require 'environment'
42 puts "delete "+File.expand_path(Environment::TMPDIR)
43 FileUtils.rm_rf(File.expand_path(Environment::TMPDIR))
44 puts "delete "+File.expand_path(Environment::LOGDIR)
45 FileUtils.rm_rf(File.expand_path(Environment::LOGDIR))
46 puts "delete "+File.expand_path(Environment::CONFROOT)
47 FileUtils.rm_rf(File.expand_path(File.join(Environment::CONFROOT, 'icons')))
48 puts "delete "+File.expand_path(Environment::CACHE)
49 FileUtils.rm_rf(File.expand_path(Environment::CACHE))
50 exit }
51 opt.on('-v', '--version', "Show mikutter version"){ |v|
52 require 'fileutils'
53 require_relative '../utils'
54 require 'environment'
55 puts Environment::NAME + ' ' + Environment::VERSION.to_s
56 exit }
57 opt.on('-h', '--help', "Show this message"){
58 @opts[:help] = true }
59
60 opt.parse!(argv)
61
62 if exec_command
63 require 'boot/prepare_plugin' # TODO: これも消したい
64 end
65 if @opts[:help]
66 puts opt
67 puts "command are:"
68 puts " generate [plugin_slug] generate plugin template at ~/.mikutter/plugin/"
69 puts " spec [directory] generate plugin spec. ex) mikutter spec ~/.mikutter/plugin/test"
70 puts " makepot generate .pot file all plugins."
71
72 Prelude.load_all
73 unless Prelude.commands.empty?
74 puts 'plugin commands are:'
75 commands = Prelude.commands.sort_by(&:full_name)
76 length = [29, commands.map { |cmd| cmd.full_name.size }.max + 1].max
77 commands.each do |cmd|
78 puts " #{cmd.full_name.ljust(length)}#{cmd.description}"
79 end
80 end
81 exit
82 end
83
84 if exec_command and argv[0]
85 Prelude.execute!(argv[0])
86 end
87 end
88 end
89 end
90
91 require_relative 'prelude'