Skip to content

Commit

Permalink
feat: get line from user input
Browse files Browse the repository at this point in the history
  • Loading branch information
halfmoon-mind committed Jun 25, 2023
1 parent c2763fc commit a49b074
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 23 deletions.
39 changes: 30 additions & 9 deletions source/app.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,31 @@
import React from 'react';
import {Text} from 'ink';

export default function App({name = 'Stranger'}) {
return (
<Text>
Hello, <Text color="green">{name}</Text>? nice to meet you.
</Text>
);
}
import { Box, Text } from 'ink';
import Enquirer from 'enquirer';

const App = () => {
const [name, setName] = React.useState();

React.useEffect(() => {
const enquirer = new Enquirer();
enquirer
.prompt({
type: 'input',
name: 'username',
message: 'What is your name?'
})
.then(answer => setName(answer.username));
}, []);


return name ? (
<Box>
<Text>Hello, {name}!</Text>
</Box>
) : (
<Box>
<Text>Welcome to our CLI App. Please input your name.</Text>
</Box>
);
};

export default App;
28 changes: 14 additions & 14 deletions source/cli.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
#!/usr/bin/env node
import React from 'react';
import {render} from 'ink';
import { render } from 'ink';
import meow from 'meow';
import App from './app.js';

const cli = meow(
`
Usage
$ up-date-cli
`
Usage
$ up-date
Options
--name Your name
Options
--name Your name
Examples
$ up-date-cli --name=Jane
Hello, Jane
`,
{
importMeta: import.meta,
},
Examples
$ up-date --name=Jane
Hello, Jane
`,
{
importMeta: import.meta,
}
);

render(<App name={cli.flags.name} />);
render(<App />);

0 comments on commit a49b074

Please sign in to comment.