Class: Lutaml::Cli::InteractiveShell::NavigationCommands
- Inherits:
-
CommandBase
- Object
- CommandBase
- Lutaml::Cli::InteractiveShell::NavigationCommands
show all
- Defined in:
- lib/lutaml/cli/interactive_shell/navigation_commands.rb
Instance Attribute Summary
Attributes inherited from CommandBase
#shell
Instance Method Summary
collapse
Methods inherited from CommandBase
#bookmarks, #config, #current_path, #current_path=, #initialize, #last_results, #last_results=, #path_history, #repository
Instance Method Details
#cmd_back(_args) ⇒ Object
97
98
99
100
101
102
103
104
105
|
# File 'lib/lutaml/cli/interactive_shell/navigation_commands.rb', line 97
def cmd_back(_args)
if path_history.size > 1
path_history.pop
self.current_path = path_history.last
puts "Changed to: #{current_path}"
else
puts OutputFormatter.warning("No previous location")
end
end
|
#cmd_cd(args) ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/lutaml/cli/interactive_shell/navigation_commands.rb', line 10
def cmd_cd(args)
if args.empty?
puts OutputFormatter.warning("Usage: cd PATH")
return
end
path = resolve_path(args[0])
pkg = repository.find_package(path)
if pkg
push_path_history
self.current_path = path
puts "Changed to: #{path}"
else
puts OutputFormatter.error("Package not found: #{path}")
end
end
|
#cmd_ls(args) ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/lutaml/cli/interactive_shell/navigation_commands.rb', line 32
def cmd_ls(args)
path = args.empty? ? current_path : resolve_path(args[0])
recursive = args.include?("-r") || args.include?("--recursive")
packages = repository.list_packages(path, recursive: recursive)
if packages.empty?
puts OutputFormatter.warning("No packages found at #{path}")
else
packages.each do |pkg|
icon = config[:icons] ? "#{EnhancedFormatter::ICONS[:package]} " : ""
puts "#{icon}#{pkg.name}"
end
puts ""
puts "Total: #{packages.size} package(s)"
end
end
|
#cmd_pwd(_args) ⇒ Object
28
29
30
|
# File 'lib/lutaml/cli/interactive_shell/navigation_commands.rb', line 28
def cmd_pwd(_args)
puts current_path
end
|
#cmd_root(_args) ⇒ Object
87
88
89
90
91
92
93
94
95
|
# File 'lib/lutaml/cli/interactive_shell/navigation_commands.rb', line 87
def cmd_root(_args)
if current_path == "ModelRoot"
puts "Already at root"
else
push_path_history
self.current_path = "ModelRoot"
puts "Changed to: ModelRoot"
end
end
|
#cmd_tree(args) ⇒ Object
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/lutaml/cli/interactive_shell/navigation_commands.rb', line 50
def cmd_tree(args)
path = args.empty? ? current_path : resolve_path(args[0])
max_depth = nil
args.each_with_index do |arg, i|
max_depth = args[i + 1].to_i if arg == "-d" && args[i + 1]
end
tree_data = repository.package_tree(path, max_depth: max_depth)
unless tree_data
puts OutputFormatter.error("Package not found: #{path}")
return
end
if config[:icons]
puts EnhancedFormatter.format_tree_with_icons(tree_data, config)
else
puts OutputFormatter.format_tree(tree_data)
end
end
|
#cmd_up(_args) ⇒ Object
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/lutaml/cli/interactive_shell/navigation_commands.rb', line 72
def cmd_up(_args)
if current_path == "ModelRoot"
puts OutputFormatter.warning("Already at root")
return
end
parts = current_path.split("::")
parts.pop
new_path = parts.empty? ? "ModelRoot" : parts.join("::")
push_path_history
self.current_path = new_path
puts "Changed to: #{current_path}"
end
|
#resolve_path(path) ⇒ Object
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
# File 'lib/lutaml/cli/interactive_shell/navigation_commands.rb', line 107
def resolve_path(path)
return path if path.start_with?("ModelRoot")
return current_path if path == "."
return "ModelRoot" if path == "/"
if path.start_with?("../")
parts = current_path.split("::")
path.scan("../").each { parts.pop }
remaining = path.gsub(/^(\.\.\/)+/, "")
new_path = parts + remaining.split("/")
new_path.join("::")
elsif path.start_with?("./")
"#{current_path}::#{path[2..]}"
else
current_path == "ModelRoot" ? path : "#{current_path}::#{path}"
end
end
|