-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of github.com:zoedsoupe/nexus
* 'main' of github.com:zoedsoupe/nexus: DSL refactor and Flags (options) parsing (#21)
- Loading branch information
Showing
19 changed files
with
1,371 additions
and
598 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,15 @@ | ||
local_without_parens = [ | ||
defcommand: 2, | ||
subcommand: 2, | ||
value: 2, | ||
flag: 2, | ||
short: 1, | ||
description: 1 | ||
] | ||
|
||
[ | ||
import_deps: [:nimble_parsec], | ||
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"], | ||
export: [locals_without_parens: [defcommand: 2]], | ||
locals_without_parens: [defcommand: 2] | ||
export: [locals_without_parens: local_without_parens], | ||
locals_without_parens: local_without_parens | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
defmodule MyCLI do | ||
@moduledoc """ | ||
MyCLI provides file operations such as copy, move, and delete using the Nexus.CLI DSL. | ||
""" | ||
|
||
use Nexus.CLI, otp_app: :nexus_cli | ||
|
||
defcommand :file do | ||
description "Performs file operations such as copy, move, and delete." | ||
|
||
subcommand :copy do | ||
description "Copies files from source to destination." | ||
|
||
value :string, required: true, as: :source | ||
value :string, required: true, as: :dest | ||
|
||
flag :level do | ||
value :integer, required: false | ||
end | ||
|
||
flag :verbose do | ||
short :v | ||
description "Enables verbose output." | ||
end | ||
|
||
flag :recursive do | ||
short :rc | ||
description "Copies directories recursively." | ||
end | ||
end | ||
|
||
subcommand :move do | ||
description "Moves files from source to destination." | ||
|
||
value :string, required: true, as: :source | ||
value :string, required: true, as: :dest | ||
|
||
flag :force do | ||
short :f | ||
description "Forces the move without confirmation." | ||
end | ||
|
||
flag :verbose do | ||
short :v | ||
description "Enables verbose output." | ||
end | ||
end | ||
|
||
subcommand :delete do | ||
description "Deletes specified files or directories." | ||
|
||
value {:list, :string}, required: true, as: :targets | ||
|
||
flag :force do | ||
short :f | ||
description "Forces deletion without confirmation." | ||
end | ||
|
||
flag :recursive do | ||
short :rc | ||
description "Deletes directories recursively." | ||
end | ||
|
||
flag :verbose do | ||
short :v | ||
description "Enables verbose output." | ||
end | ||
end | ||
end | ||
|
||
@impl Nexus.CLI | ||
def handle_input([:file, :copy], %{args: args, flags: flags}) do | ||
if flags.verbose do | ||
IO.puts("Copying from #{args.source} to #{args.dest}") | ||
end | ||
|
||
if flags.recursive do | ||
IO.puts("Recursive copy enabled") | ||
end | ||
|
||
# Implement actual copy logic here | ||
IO.puts("Copied #{args.source} to #{args.dest}") | ||
:ok | ||
end | ||
|
||
def handle_input([:file, :move], %{args: args, flags: flags}) do | ||
if flags.verbose do | ||
IO.puts("Moving from #{args.source} to #{args.dest}") | ||
end | ||
|
||
if flags.force do | ||
IO.puts("Force move enabled") | ||
end | ||
|
||
# Implement actual move logic here | ||
IO.puts("Moved #{args.source} to #{args.dest}") | ||
:ok | ||
end | ||
|
||
def handle_input([:file, :delete], %{args: args, flags: flags}) do | ||
if flags.verbose do | ||
IO.puts("Deleting targets: #{Enum.join(args.targets, ", ")}") | ||
end | ||
|
||
if flags.recursive do | ||
IO.puts("Recursive delete enabled") | ||
end | ||
|
||
if flags.force do | ||
IO.puts("Force delete enabled") | ||
end | ||
|
||
# Implement actual delete logic here | ||
Enum.each(args.targets, fn target -> | ||
IO.puts("Deleted #{target}") | ||
end) | ||
|
||
:ok | ||
end | ||
|
||
def handle_input(command, input) do | ||
IO.puts("Unknown command or invalid parameters") | ||
IO.inspect(command, label: "CMD") | ||
IO.inspect(input, label: "INPUT") | ||
:error | ||
end | ||
end |
Oops, something went wrong.