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
84
85
86
87
88
89
90
91
92
|
# File 'lib/lutaml/cli/interactive_shell/navigation_commands.rb', line 84
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
|
# 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
display_packages(packages)
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
74
75
76
77
78
79
80
81
82
|
# File 'lib/lutaml/cli/interactive_shell/navigation_commands.rb', line 74
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
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/lutaml/cli/interactive_shell/navigation_commands.rb', line 45
def cmd_tree(args)
path = args.empty? ? current_path : resolve_path(args[0])
max_depth = (args)
tree_data = repository.package_tree(path, max_depth: max_depth)
unless tree_data
puts OutputFormatter.error("Package not found: #{path}")
return
end
puts format_tree(tree_data)
end
|
#cmd_up(_args) ⇒ Object
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/lutaml/cli/interactive_shell/navigation_commands.rb', line 59
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_child_path(path) ⇒ Object
104
105
106
|
# File 'lib/lutaml/cli/interactive_shell/navigation_commands.rb', line 104
def resolve_child_path(path)
"#{current_path}::#{path[2..]}"
end
|
#resolve_path(path) ⇒ Object
94
95
96
97
98
99
100
101
102
|
# File 'lib/lutaml/cli/interactive_shell/navigation_commands.rb', line 94
def resolve_path(path)
return path if path.start_with?("ModelRoot")
return current_path if path == "."
return "ModelRoot" if path == "/"
return resolve_parent_path(path) if path.start_with?("../")
return resolve_child_path(path) if path.start_with?("./")
resolve_simple_path(path)
end
|
#resolve_simple_path(path) ⇒ Object
108
109
110
|
# File 'lib/lutaml/cli/interactive_shell/navigation_commands.rb', line 108
def resolve_simple_path(path)
current_path == "ModelRoot" ? path : "#{current_path}::#{path}"
end
|