Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add elixir support #31

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions compiled_starters/elixir/.codecrafters/compile.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh
#
# This script is used to compile your program on CodeCrafters
#
# This runs before .codecrafters/run.sh
#
# Learn more: https://codecrafters.io/program-interface

set -e # Exit on failure

mix escript.build
mv codecrafters_shell /tmp/codecrafters-build-shell-elixir
11 changes: 11 additions & 0 deletions compiled_starters/elixir/.codecrafters/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh
#
# This script is used to run your program on CodeCrafters
#
# This runs after .codecrafters/compile.sh
#
# Learn more: https://codecrafters.io/program-interface

set -e # Exit on failure

exec /tmp/codecrafters-build-shell-elixir "$@"
4 changes: 4 additions & 0 deletions compiled_starters/elixir/.formatter.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Used by "mix format"
[
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
]
1 change: 1 addition & 0 deletions compiled_starters/elixir/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto
27 changes: 27 additions & 0 deletions compiled_starters/elixir/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Ignore the compiled binary
/codecrafters_shell

# The directory Mix will write compiled artifacts to.
/_build/

# If you run "mix test --cover", coverage assets end up here.
/cover/

# The directory Mix downloads your dependencies sources to.
/deps/

# Where third-party dependencies like ExDoc output generated docs.
/doc/

# Ignore .fetch files in case you like to edit your project deps locally.
/.fetch

# If the VM crashes, it generates a dump, let's ignore it too.
erl_crash.dump

# Also ignore archive artifacts (built via "mix archive.build").
*.ez

# Ignore package tarball (built via "mix hex.build").
app-*.tar

35 changes: 35 additions & 0 deletions compiled_starters/elixir/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
![progress-banner](https://codecrafters.io/landing/images/default_progress_banners/shell.png)

This is a starting point for Elixir solutions to the
["Build Your Own Shell" Challenge](https://app.codecrafters.io/courses/shell/overview).

In this challenge, you'll build your own POSIX compliant shell that's capable of
interpreting shell commands, running external programs and builtin commands like
cd, pwd, echo and more. Along the way, you'll learn about shell command parsing,
REPLs, builtin commands, and more.

**Note**: If you're viewing this repo on GitHub, head over to
[codecrafters.io](https://codecrafters.io) to try the challenge.

# Passing the first stage

The entry point for your `shell` implementation is in `lib/main.ex`. Study and
uncomment the relevant code, and push your changes to pass the first stage:

```sh
git add .
git commit -m "pass 1st stage" # any msg
git push origin master
```

Time to move on to the next stage!

# Stage 2 & beyond

Note: This section is for stages 2 and beyond.

1. Ensure you have `mix` installed locally
1. Run `./your_program.sh` to run your program, which is implemented in
`lib/main.ex`.
1. Commit your changes and run `git push origin master` to submit your solution
to CodeCrafters. Test output will be streamed to your terminal.
11 changes: 11 additions & 0 deletions compiled_starters/elixir/codecrafters.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Set this to true if you want debug logs.
#
# These can be VERY verbose, so we suggest turning them off
# unless you really need them.
debug: false

# Use this to change the Elixir version used to run your code
# on Codecrafters.
#
# Available versions: elixir-1.17
language_pack: elixir-1.17
9 changes: 9 additions & 0 deletions compiled_starters/elixir/lib/main.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
defmodule CLI do
def main(_args) do
# Uncomment this block to pass the first stage
# IO.write("$ ")

# Wait for user input
IO.read(:line)
end
end
30 changes: 30 additions & 0 deletions compiled_starters/elixir/mix.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
defmodule App.MixProject do
# NOTE: You do not need to change anything in this file.
use Mix.Project

def project do
[
app: :codecrafters_shell,
version: "1.0.0",
elixir: "~> 1.17",
start_permanent: Mix.env() == :prod,
deps: deps(),
escript: [main_module: CLI]
]
end

# Run "mix help compile.app" to learn about applications.
def application do
[
extra_applications: [:logger]
]
end

# Run "mix help deps" to learn about dependencies.
defp deps do
[
# {:dep_from_hexpm, "~> 0.3.0"},
# {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"}
]
end
end
25 changes: 25 additions & 0 deletions compiled_starters/elixir/your_program.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/sh
#
# Use this script to run your program LOCALLY.
#
# Note: Changing this script WILL NOT affect how CodeCrafters runs your program.
#
# Learn more: https://codecrafters.io/program-interface

set -e # Exit early if any commands fail

# Copied from .codecrafters/compile.sh
#
# - Edit this to change how your program compiles locally
# - Edit .codecrafters/compile.sh to change how your program compiles remotely
(
cd "$(dirname "$0")" # Ensure compile steps are run within the repository directory
mix escript.build
mv codecrafters_shell /tmp/codecrafters-build-shell-elixir
)

# Copied from .codecrafters/run.sh
#
# - Edit this to change how your program runs locally
# - Edit .codecrafters/run.sh to change how your program runs remotely
exec /tmp/codecrafters-build-shell-elixir "$@"
20 changes: 20 additions & 0 deletions dockerfiles/elixir-1.17.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# syntax=docker/dockerfile:1.7-labs
FROM elixir:1.17.2-alpine

# Ensures the container is re-built if dependency files change
ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="mix.exs"

WORKDIR /app

# .git & README.md are unique per-repository. We ignore them on first copy to prevent cache misses
COPY --exclude=.git --exclude=README.md . /app

# Install & cache deps
RUN .codecrafters/compile.sh

# If _build directory exists, move it to /app-cached
RUN mkdir -p /app-cached
RUN if [ -d "/app/_build" ]; then mv /app/_build /app-cached; fi

# Once the heavy steps are done, we can copy all files back
COPY . /app
12 changes: 12 additions & 0 deletions solutions/elixir/01-oo8/code/.codecrafters/compile.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh
#
# This script is used to compile your program on CodeCrafters
#
# This runs before .codecrafters/run.sh
#
# Learn more: https://codecrafters.io/program-interface

set -e # Exit on failure

mix escript.build
mv codecrafters_shell /tmp/codecrafters-build-shell-elixir
11 changes: 11 additions & 0 deletions solutions/elixir/01-oo8/code/.codecrafters/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh
#
# This script is used to run your program on CodeCrafters
#
# This runs after .codecrafters/compile.sh
#
# Learn more: https://codecrafters.io/program-interface

set -e # Exit on failure

exec /tmp/codecrafters-build-shell-elixir "$@"
4 changes: 4 additions & 0 deletions solutions/elixir/01-oo8/code/.formatter.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Used by "mix format"
[
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
]
1 change: 1 addition & 0 deletions solutions/elixir/01-oo8/code/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto
27 changes: 27 additions & 0 deletions solutions/elixir/01-oo8/code/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Ignore the compiled binary
/codecrafters_shell

# The directory Mix will write compiled artifacts to.
/_build/

# If you run "mix test --cover", coverage assets end up here.
/cover/

# The directory Mix downloads your dependencies sources to.
/deps/

# Where third-party dependencies like ExDoc output generated docs.
/doc/

# Ignore .fetch files in case you like to edit your project deps locally.
/.fetch

# If the VM crashes, it generates a dump, let's ignore it too.
erl_crash.dump

# Also ignore archive artifacts (built via "mix archive.build").
*.ez

# Ignore package tarball (built via "mix hex.build").
app-*.tar

35 changes: 35 additions & 0 deletions solutions/elixir/01-oo8/code/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
![progress-banner](https://codecrafters.io/landing/images/default_progress_banners/shell.png)

This is a starting point for Elixir solutions to the
["Build Your Own Shell" Challenge](https://app.codecrafters.io/courses/shell/overview).

In this challenge, you'll build your own POSIX compliant shell that's capable of
interpreting shell commands, running external programs and builtin commands like
cd, pwd, echo and more. Along the way, you'll learn about shell command parsing,
REPLs, builtin commands, and more.

**Note**: If you're viewing this repo on GitHub, head over to
[codecrafters.io](https://codecrafters.io) to try the challenge.

# Passing the first stage

The entry point for your `shell` implementation is in `lib/main.ex`. Study and
uncomment the relevant code, and push your changes to pass the first stage:

```sh
git add .
git commit -m "pass 1st stage" # any msg
git push origin master
```

Time to move on to the next stage!

# Stage 2 & beyond

Note: This section is for stages 2 and beyond.

1. Ensure you have `mix` installed locally
1. Run `./your_program.sh` to run your program, which is implemented in
`lib/main.ex`.
1. Commit your changes and run `git push origin master` to submit your solution
to CodeCrafters. Test output will be streamed to your terminal.
11 changes: 11 additions & 0 deletions solutions/elixir/01-oo8/code/codecrafters.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Set this to true if you want debug logs.
#
# These can be VERY verbose, so we suggest turning them off
# unless you really need them.
debug: false

# Use this to change the Elixir version used to run your code
# on Codecrafters.
#
# Available versions: elixir-1.17
language_pack: elixir-1.17
8 changes: 8 additions & 0 deletions solutions/elixir/01-oo8/code/lib/main.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
defmodule CLI do
def main(_args) do
IO.write("$ ")

# Wait for user input
IO.read(:line)
end
end
30 changes: 30 additions & 0 deletions solutions/elixir/01-oo8/code/mix.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
defmodule App.MixProject do
# NOTE: You do not need to change anything in this file.
use Mix.Project

def project do
[
app: :codecrafters_shell,
version: "1.0.0",
elixir: "~> 1.17",
start_permanent: Mix.env() == :prod,
deps: deps(),
escript: [main_module: CLI]
]
end

# Run "mix help compile.app" to learn about applications.
def application do
[
extra_applications: [:logger]
]
end

# Run "mix help deps" to learn about dependencies.
defp deps do
[
# {:dep_from_hexpm, "~> 0.3.0"},
# {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"}
]
end
end
25 changes: 25 additions & 0 deletions solutions/elixir/01-oo8/code/your_program.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/sh
#
# Use this script to run your program LOCALLY.
#
# Note: Changing this script WILL NOT affect how CodeCrafters runs your program.
#
# Learn more: https://codecrafters.io/program-interface

set -e # Exit early if any commands fail

# Copied from .codecrafters/compile.sh
#
# - Edit this to change how your program compiles locally
# - Edit .codecrafters/compile.sh to change how your program compiles remotely
(
cd "$(dirname "$0")" # Ensure compile steps are run within the repository directory
mix escript.build
mv codecrafters_shell /tmp/codecrafters-build-shell-elixir
)

# Copied from .codecrafters/run.sh
#
# - Edit this to change how your program runs locally
# - Edit .codecrafters/run.sh to change how your program runs remotely
exec /tmp/codecrafters-build-shell-elixir "$@"
11 changes: 11 additions & 0 deletions solutions/elixir/01-oo8/diff/lib/main.ex.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@@ -1,9 +1,8 @@
defmodule CLI do
def main(_args) do
- # Uncomment this block to pass the first stage
- # IO.write("$ ")
+ IO.write("$ ")

# Wait for user input
IO.read(:line)
end
end
16 changes: 16 additions & 0 deletions solutions/elixir/01-oo8/explanation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
The entry point for your Shell implementation is in `lib/main.ex`.

Study and uncomment the relevant code:

```elixir
# Uncomment this block to pass the first stage
IO.write("$ ")
```

Push your changes to pass the first stage:

```
git add .
git commit -m "pass 1st stage" # any msg
git push origin master
```
Loading
Loading