Module: Simp::Cli::Config::SafeApplying
- Included in:
- ActionItem, Item::GrubPassword, Item::UseFips
- Defined in:
- lib/simp/cli/config/item.rb
Overview
mixin that provides common logic for safe_apply()
Instance Method Summary collapse
Instance Method Details
#safe_apply ⇒ Object
403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 |
# File 'lib/simp/cli/config/item.rb', line 403 def safe_apply extra = '' not_root_msg = '' if !@allow_user_apply not_root_msg = ENV.fetch('USER') == 'root' ? '' : ' [**user is not root**] ' end if @skip_apply || (not_root_msg.size != 0) extra = "<%= color( %q{(skipping apply#{not_root_msg})}, MAGENTA, BOLD)%> " say( "#{extra}#{@key}" ) unless @silent if !(@value.nil? || @value.class == TrueClass || @value.class == FalseClass || @value.empty?) say( "= '<%= color( %q{#{@value}}, BOLD )%>'\n" ) unless @silent end else extra = "<%= color( %q{(applying changes)}, GREEN, BOLD)%> " say( "#{extra}for #{@key}\n" ) unless @silent begin result = apply if result extra = "<%= color( %q{(change applied)}, GREEN, BOLD)%> " else extra = "<%= color( %q{(change failed)}, RED, BOLD)%> " end say( "#{extra}for #{@key}\n" ) unless @silent rescue Exception => e extra = "<%= color( %q{(change failed)}, RED, BOLD) %> " say( "#{extra}for #{@key}:\n#{e.}" ) say "<%= color( %q{#{e..to_s.gsub( /^/, ' ' )}}, RED) %> \n" # Some failures should be punished by death fail e if @die_on_apply_fail end end end |